how to have one of the column in gridview to be an image?
Just store the image URL in the DataTable rather than the actual image. Then, use a TemplateField
in your GridView and put an Image in the ItemTemplate
:
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrlColumn") %>' ... />
</ItemTemplate>
</asp:TemplateField>
You can also use an ImageField
:
<asp:ImageField DataImageUrlField="ImageNameColumn" DataImageUrlFormatString="/images/{0}"></asp:ImageField>
EDIT
When declaring columns, try this instead:
dt.Columns.Add("Image", typeof(string));
And to set the value of the image column, try this:
dr.SetField<string>("Image", "img.png");