Displaying Custom Messages / Images with NULL Value in ASP.NET GridView in C#

Sometimes while binding record to Gridview we see that some columns are empty for some rows, it happens because GridView displays empty for null value. But if we want to show some Custom data or Images that can be possible using BoundField.

1

 

Sometimes developers use GridView_RowDataBound() to override the NULL value with proper message. But Instead of overriding the value, we can use NullDisplayText to display proper message when the value for that particular field is NULL .

image thumb17 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

 

Once we mentioned NullDisplayText=”No Data” for every field for that Bound Filed which having NULL value will be replace by “No Data”
image thumb18 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

Even we can customize the Text with HTML Formatting as shown in below.

image thumb19 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

image thumb20 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

One more interesting point is, we  can also display Images for NULL Value

image thumb21 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

image thumb22 Displaying Custom Messages / Images with NULL Value in ASP.NET GridView

 

Advertisements

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