Showing a "Image" in a Datagrid
-
Hi all, I am trying to show a "Image" in a DataGrid. I have a new class I created that has 3 properties that are string and one that is of type image. I create an Array of this class, and make the DataGrid source the Array. But the image column comes up as a red cross in a white background, i.e. its not an image. Can anyone give me some idea of best practice to show an image in a DataGrid please? Regards Tony
-
Hi all, I am trying to show a "Image" in a DataGrid. I have a new class I created that has 3 properties that are string and one that is of type image. I create an Array of this class, and make the DataGrid source the Array. But the image column comes up as a red cross in a white background, i.e. its not an image. Can anyone give me some idea of best practice to show an image in a DataGrid please? Regards Tony
Hi Tony, hope the following code works.
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.Image anImagine ;
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item )
{
anImagine = ((System.Web.UI.WebControls.Image)e.Item.Cells[1].Controls[1]); anImagine.ImageUrl="icons/" + e.Item.Cells[0].Text.ToString() + ".gif";
}
}Keshav Kamat :) India
-
Hi Tony, hope the following code works.
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.Image anImagine ;
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item )
{
anImagine = ((System.Web.UI.WebControls.Image)e.Item.Cells[1].Controls[1]); anImagine.ImageUrl="icons/" + e.Item.Cells[0].Text.ToString() + ".gif";
}
}Keshav Kamat :) India