Clean Complex Databinding in ASP.Net
2009 April 2
So I needed to do a little CRUD ListView for a simple app I’m working on. One of the columns is an image path that I was using an Image object to display. The object got vetoed and I’m going with text now so I wanted a clean way to either show a simple text link to pop the image on a new tab or show that no image was available. I went with this in the template:
<td><%# GenerateImageField(Eval("ImagePath")) %> </td>
public string GenerateImageField(object dataItem){
if (dataItem == null || string.IsNullOrEmpty(dataItem.ToString()))
{
return "No Image";
}
return @"<a href='"+ dataItem.ToString() +@"' target='_blank'>Image</a>";
}
This works out rather well.
