Skip to content

Clean Complex Databinding in ASP.Net

April 2, 2009

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.

croppercapture1
Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: