Click here to Skip to main content
14,770,661 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I want to retrieve the image and show it in the gridview. I have stored the image in a folder and stored the image path in the SQL server. And I want to retrieve the image in Gridview.

Can any one help me?
Posted
Comments
King Fisher 27-Nov-13 0:50am
   
your Code?
Member 10419145 27-Nov-13 1:33am
   
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged

Try
If Not IsDBNull(GridView1.Rows(e.RowIndex).Cells("Qimage").Value) Then


'Get image data from gridview column.



''Initialize image variable
Dim newImage As Image
'Read image data into a memory stream
Using ms As New MemoryStream(ReadFile(GridView1.Rows(e.RowIndex).Cells("Qimage").Value), 0, ReadFile(GridView1.Rows(e.RowIndex).Cells("Qimage").Value).Length)
ms.Write(ReadFile(GridView1.Rows(e.RowIndex).Cells("Qimage").Value), 0, ReadFile(GridView1.Rows(e.RowIndex).Cells("Qimage").Value).Length)

'Set image variable value using memory stream.
newImage = Image.FromStream(ms, True)
End Using

'set picture
Image1.Image = newImage
End If

Catch ex As Exception
End Try


Private Function ReadFile(ByVal sPath As String) As Byte()
'Initialize byte array with a null value initially.
Dim data As Byte() = Nothing

'Use FileInfo object to get file size.
Dim fInfo As New FileInfo(sPath)
Dim numBytes As Long = fInfo.Length

'Open FileStream to read file
Dim fStream As New FileStream(sPath, FileMode.Open, FileAccess.Read)

'Use BinaryReader to read file stream into byte array.
Dim br As New BinaryReader(fStream)

'When you use BinaryReader, you need to supply number of bytes to read from file.
'In this case we want to read entire file. So supplying total number of bytes.
data = br.ReadBytes(CInt(numBytes))
Return data
End Function
On the click of "Select" in the gridview I need to get the Desired image in image control.

I tried this in Vb.net, on the Datagridview cell click event but that does not works here.

Can you help me in this?

   
Comments
Member 10419145 27-Nov-13 1:30am
   
On my Gridview I am getting only path of the image "C:\Documents and Settings\sathish.kumar\Desktop\RegIR_NEW\RegIR\bin\Debug\..\..\Images\5-Q-IMG.jpg" and on click of "select" link in the gridview. I must get the respective image in the image control


I tried this in Vb.net, on the Datagridview cell click event but that does not works here.

Can you help me in this?
   
Comments
Member 10419145 27-Nov-13 1:39am
   
On my Gridview I am getting only path of the image "C:\Documents and Settings\sathish.kumar\Desktop\RegIR_NEW\RegIR\bin\Debug\..\..\Images\5-Q-IMG.jpg" and on click of "select" link in the gridview. I must get the respective image in the image control


I tried this in Vb.net, on the Datagridview cell click event but that does not works here.

Can you help me in this?
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900