DataGrid TemplateColumns help
ASP.NET
2
Posts
2
Posters
0
Views
1
Watching
-
plz help i add image at templetcolumn but i wanna to change its url from row to row from the code thankx
Hi there, If you want to change the ImageUrl property of an image object, you first need to get a reference to that image control with the help of the FindControl method, then you can set the ImageUrl property. The sample code looks something like this:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//Here, I assume the image's id is 'imgID'
Image imgControl = e.Item.FindControl("imgID") as Image;
if(imgControl != null)
{
imgControl.ImageUrl = "Images/logo.gif";
}
}
}