I want to add image to GridView cell with below code but doesn’t show image
//aspx
<asp:TemplateField HeaderText="image">
<ItemTemplate>
<asp:Image ID="img" runat="server" Width="100px" Height="100px" />
</ItemTemplate>
//.cs -> In page_Load
for (int i = 0; i < GridView1.Rows.Count; i++)
{
Image img = (Image)GridView1.Rows[i].FindControl("img");
img.ImageUrl = path of image;
}//for
You can use
RowDataBoundevent to change something inside a GridView Row.Or you can use a
foreachstatment to loop in Rows collection and change the path of image. this code could be on the Page_Load event.Edits
You cannot set the image out of the solution. Do to this, you have to create an Handler (.ashx file) and pass the name of your image on C: and return the a byte[], something like this:
And on your page, set it by handler passing a
imageparameter in url: