How to display blank instead of   in BoundColumn if null

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2FsdmluIEtE?=, Jul 8, 2005.

  1. 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
    =?Utf-8?B?Q2FsdmluIEtE?=, Jul 8, 2005
    #1
    1. Advertising

  2. 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


    "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.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
    >
    =?Utf-8?B?bG9uZG9uIGNhbGxpbmc=?=, Jul 8, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tina

    &nbsp; and null fields

    Tina, Oct 18, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    742
    Mythran
    Oct 19, 2005
  2. Robert Kattke
    Replies:
    0
    Views:
    428
    Robert Kattke
    Dec 31, 2003
  3. =?utf-8?B?5LiA6aaW6K+X?=

    How to convert "&nbsp;" in a string to blank space?

    =?utf-8?B?5LiA6aaW6K+X?=, Oct 30, 2006, in forum: Python
    Replies:
    7
    Views:
    10,776
    Frederic Rentsch
    Oct 30, 2006
  4. mesut
    Replies:
    0
    Views:
    559
    mesut
    Jun 29, 2007
  5. hotkitty

    Parsing CSV and "&nbsp;&nbsp;"

    hotkitty, Oct 9, 2008, in forum: Perl Misc
    Replies:
    9
    Views:
    326
Loading...

Share This Page