How To Create Image Column In GridView?
There are two possible scenarios:
1. Database contains only image file names as strings, and images are stored in file system.
2. Database contains file names and also images stored in binary column in database.
If images are stored in file system and database contains only file names, you can use this two common solutions:
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False">
<Columns>
<%--
1. Fast and easy way with ImageField Column --%>
<asp:ImageField
DataImageUrlField="ImageFileName"
DataImageUrlFormatString="~/Images/{0}"></asp:ImageField>
<%--
2. Or,
you can do it on old way with template column. Although more complicated, this
method provides more flexibility in some scenarios
--%>
<asp:TemplateField>
<ItemTemplate>
<img
src='~/Images/<%#DataBinder.Eval
(Container.DataItem, "ImageFileName")%>'>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
If your images are stored in database in binary form, see Storing Images to Database and Retrieving to GridView tutorial.
Related articles:
1. Debugging with "Stepping" and "Data Viewing" features
2. SQL Queries For Paging In ASP.NET