Image Displaying in Datagrid
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string sEmpImgPath = String.Empty;
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
//For Displaying Image
//-->Start
System.Web.UI.WebControls.Image ImgPhoto =
(System.Web.UI.WebControls.Image)
e.Item.Cells[4].FindControl("ImgPhoto");
//Cell which is mark visible false and contain
//Image path.
sEmpImgPath = e.Item.Cells[5].Text;
if(ImgPhoto != null)
{
if(sEmpImgPath.Length != 0 &&
sEmpImgPath != " ") //Emp Pic Avaliable
{
ImgPhoto.ImageUrl = sEmpImgPath;
}
else
{
ImgPhoto.ImageUrl =
"EmpPic\\default.gif";
}
}
//-->End
}
}
No comments:
Post a Comment