Hi All,
I new to asp.net. I am creating a web application. The purpose of this application is that it should display the datas and images from database in Gridview and on "Click" of "Selct" option in Gridview, the datas in database must be displayed in textbox and image must be displayed in image control.
The datas and image are stored in database using vb.net application and image is stored as Filepath.
The Filepath for the image is the vb.net application "start up point"
i.e some think like
"C:\Documents and Settings\sathish\Desktop\application name\application name folder\bin\Debug\..\..\" & imagesfoldername\filename.
Exactly it will be
"C:\Documents and Settings\sathish\Desktop\RegIR_NEW\RegIR\bin\Debug\..\..\Images\6-Q-IMG.jpg"
When I click on retrieve button which I created in "asp.net" application, In Gridview I am getting the image path as said above. In gridview properties I have selected the "Auto Generate Select Button - TRUE"
MY QUESTION IS WHEN I CLICK ON THE "selct" option in Gridview, I must get the image in Image control.
All other data like text I can get in textbox by using "Gridview SelectedIndex" Event.
IS THERE ANY CODING EXAMPLE THAT CAN READ THE FILEPATH AND PROVIDE ME THE IMAGE IN "image control"
I have used memory stream in vb.net to show image in picture box. But I cannot follow this here?
Can any one help me on this?
My coding in vb.net to retrieve image is:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
If (i = DataGridView1.Rows.Count - 1) Then
Exit Sub
End If
Me.TextBox3.Text = DataGridView1.Item(1, i).Value
Me.TextBox4.Text = DataGridView1.Item(2, i).Value
Try
If Not IsDBNull(DataGridView1.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(DataGridView1.Rows(e.RowIndex).Cells("Qimage").Value), 0, ReadFile(DataGridView1.Rows(e.RowIndex).Cells("Qimage").Value).Length)
ms.Write(ReadFile(DataGridView1.Rows(e.RowIndex).Cells("Qimage").Value), 0, ReadFile(DataGridView1.Rows(e.RowIndex).Cells("Qimage").Value).Length)
'Set image variable value using memory stream.
newImage = Image.FromStream(ms, True)
End Using
'set picture
PictureBox1.Image = newImage
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Private Function ReadFile(ByVal sPath As String) As Byte()
Dim data As Byte() = Nothing
Dim fInfo As New FileInfo(sPath)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(sPath, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fStream)
data = br.ReadBytes(CInt(numBytes))
Return data
End Function