Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to display blank instead of   in BoundColumn if null

Reply
Thread Tools

How to display blank instead of   in BoundColumn if null

 
 
=?Utf-8?B?Q2FsdmluIEtE?=
Guest
Posts: n/a
 
      07-08-2005
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[i].ToString().Trim() == System.DBNull.Value.ToString())
{
e.Item.Cells[i].Text = "";
}
}

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

Any suggestion is greatly appreciated.

KD

 
Reply With Quote
 
 
 
 
=?Utf-8?B?bG9uZG9uIGNhbGxpbmc=?=
Guest
Posts: n/a
 
      07-08-2005
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[i] is DBNull.Value){}


HTH jd


"Calvin KD" wrote:

> 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[i].ToString().Trim() == System.DBNull.Value.ToString())
> {
> e.Item.Cells[i].Text = "";
> }
> }
>
> PS. It's a web form, not a windows form, it if makes any difference.
>
> Any suggestion is greatly appreciated.
>
> KD
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
blank CD-R and blank DVD-R not recognized by Vista 64 Ultimate =?Utf-8?B?R3JlZyBLaXJrcGF0cmljaw==?= Windows 64bit 13 11-07-2007 12:23 PM
Boundcolumn or TemplateField when to use Boundcolumn and when TemplateField ???? mesut ASP .Net 0 06-29-2007 10:17 AM
Why use "return (null);" instead of "return null;" ? Carl Java 21 08-24-2006 04:33 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM



Advertisments