0 Replies - 249 Views - Last Post: 29 April 2012 - 03:20 AM

#1 John11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 17-March 12

How to display thumbnail instead of original image in Gridview

Posted 29 April 2012 - 03:20 AM

Hello, I am using visual studio 2010 with VB. I have a data table in my database called photo with ID(int, auto increment), FileName(varchar(50)), FilePath(varchar(50)). In my "Expert.aspx" page I have a button that uploads photos and inserts them into my database. In my "Photos.aspx" page I have a gridview that is bounded using an sqldatasource to the Photo table.
I added an image field in the gridview so that I can display the photos.
The problem is that the photos are displayed with their original size. I want them to be displayed in small sizes like thumbnails.

I have this code on upload:
If FileUpload1.HasFile Then
            Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)

            FileUpload1.SaveAs(Server.MapPath("Photos/Cars/" & FileName))

            Dim connString As ConnectionStringSettings
            connString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
            Dim con As New SqlConnection(connString.ConnectionString)
            Dim strQuery As String = "INSERT INTO Photo (FileName, FilePath) VALUES(@FileName, @FilePath)"
            Dim cmd As New SqlCommand(strQuery)
            cmd.Parameters.AddWithValue("@FileName", FileName)
            cmd.Parameters.AddWithValue("@FilePath", "Photos/Cars/" & FileName)
            cmd.CommandType = CommandType.Text
            cmd.Connection = con
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End If

        If FileUpload2.HasFile Then
            Dim FileName As String = Path.GetFileName(FileUpload2.PostedFile.FileName)

            FileUpload2.SaveAs(Server.MapPath("Photos/Cars/" & FileName))

            Dim connString As ConnectionStringSettings
            connString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
            Dim con As New SqlConnection(connString.ConnectionString)
            Dim strQuery As String = "INSERT INTO Photo (FileName, FilePath) VALUES(@FileName, @FilePath)"
            Dim cmd As New SqlCommand(strQuery)
            cmd.Parameters.AddWithValue("@FileName", FileName)
            cmd.Parameters.AddWithValue("@FilePath", "Photos/Cars/" & FileName)
            cmd.CommandType = CommandType.Text
            cmd.Connection = con
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End If

        If FileUpload3.HasFile Then
            Dim FileName As String = Path.GetFileName(FileUpload3.PostedFile.FileName)

            FileUpload3.SaveAs(Server.MapPath("Photos/Cars/" & FileName))

            Dim connString As ConnectionStringSettings
            connString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString")
            Dim con As New SqlConnection(connString.ConnectionString)
            Dim strQuery As String = "INSERT INTO Photo (FileName, FilePath) VALUES(@FileName, @FilePath)"
            Dim cmd As New SqlCommand(strQuery)
            cmd.Parameters.AddWithValue("@FileName", FileName)
            cmd.Parameters.AddWithValue("@FilePath", "Photos/Cars/" & FileName)
            cmd.CommandType = CommandType.Text
            cmd.Connection = con
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()



Thank You.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1