how to display an image in gridview
-
i have uploaded the image file using asp fileupload control. i am uploading files to this folder: F:\MySite\FileManager\MyUserName saved the file name and file path to database. in my database i have DocumetName TestImage.JPG and Path F:\MySite\FileManager\MyUserName\TestImage.JPG
<asp:TemplateField headertext="picture">
<ItemTemplate>
<asp:Image ID="Image2" width="40" runat="server" imageurl='<%# Eval("DocumentName") %>' /> <br/>
</itemtemplate>
</asp:TemplateField>i tried like this(use Path instead of DocumentName) aslo but it doesn't show any image and no error also
<asp:TemplateField headertext="picture">
<ItemTemplate>
<asp:Image ID="Image2" width="40" runat="server" imageurl='<%# Eval("Path") %>' /> <br/>
</itemtemplate>
</asp:TemplateField>i am using this to get all file details
Private Sub GetAllTheImages()
' Declare objects... Dim objConnection As SqlConnection = New \_ SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MY\\SQLEXPRESS") objConnection.Open() Dim myCommand As New System.Data.SqlClient.SqlCommand() myCommand.Connection = objConnection myCommand.CommandText = "GetAllTheImages" myCommand.CommandType = CommandType.StoredProcedure Dim param As New System.Data.SqlClient.SqlParameter() Dim myAdapter As New SqlDataAdapter(myCommand) myAdapter.Fill(GetAllTheImages) Dim reader As SqlDataReader = myCommand.ExecuteReader() GV1.DataSource = GetAllTheImages GV1.DataBind() objConnection.Close() End Sub
-
i have uploaded the image file using asp fileupload control. i am uploading files to this folder: F:\MySite\FileManager\MyUserName saved the file name and file path to database. in my database i have DocumetName TestImage.JPG and Path F:\MySite\FileManager\MyUserName\TestImage.JPG
<asp:TemplateField headertext="picture">
<ItemTemplate>
<asp:Image ID="Image2" width="40" runat="server" imageurl='<%# Eval("DocumentName") %>' /> <br/>
</itemtemplate>
</asp:TemplateField>i tried like this(use Path instead of DocumentName) aslo but it doesn't show any image and no error also
<asp:TemplateField headertext="picture">
<ItemTemplate>
<asp:Image ID="Image2" width="40" runat="server" imageurl='<%# Eval("Path") %>' /> <br/>
</itemtemplate>
</asp:TemplateField>i am using this to get all file details
Private Sub GetAllTheImages()
' Declare objects... Dim objConnection As SqlConnection = New \_ SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MY\\SQLEXPRESS") objConnection.Open() Dim myCommand As New System.Data.SqlClient.SqlCommand() myCommand.Connection = objConnection myCommand.CommandText = "GetAllTheImages" myCommand.CommandType = CommandType.StoredProcedure Dim param As New System.Data.SqlClient.SqlParameter() Dim myAdapter As New SqlDataAdapter(myCommand) myAdapter.Fill(GetAllTheImages) Dim reader As SqlDataReader = myCommand.ExecuteReader() GV1.DataSource = GetAllTheImages GV1.DataBind() objConnection.Close() End Sub
it's simple you just have to add a ImageField in Gridview. Just select the Gridview & click on the arrow shown on Right side(Gridview Tasks)and Add New Column -->select ImageField(Choose a Field Type) & give your column name i.e the column having Path , used in the query to bind the gridview,in Data field If still not getting then revert back on my mail Id
Darshana Pathak