How to display blank instead of   in BoundColumn if null

G

Guest

Hi everyone,
Can someone show me how to display an empty string in a boundcolumn of a
datagrid when the data source item is NULL. Datagrid by default displays the
and that's BAD!!!!!
I've tried the following in the ItemDataBound event but it gave me an
"invalid cast" error:

DataRowView dataRowView = (DataRowView)e.Item.DataItem;
for (int i=0; i<e.Item.Cells.Count - 1; i++)
{
if (dataRowView.ToString().Trim() == System.DBNull.Value.ToString())
{
e.Item.Cells.Text = "";
}
}

PS. It's a web form, not a windows form, it if makes any difference.

Any suggestion is greatly appreciated.

KD
 
G

Guest

Hi Calvin, DBNull.Value is a reference to a (Singleton) so you need to
compare objects. In VB it is

If drv(i) Is DBNull.Value Then

In C#:
if(drv is DBNull.Value){}


HTH jd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top