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

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

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:
    945
    Mythran
    Oct 19, 2005
  2. Robert Kattke
    Replies:
    0
    Views:
    566
    Robert Kattke
    Dec 31, 2003
  3. Carl
    Replies:
    21
    Views:
    1,402
    Patricia Shanahan
    Aug 24, 2006
  4. =?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:
    11,667
    Frederic Rentsch
    Oct 30, 2006
  5. mesut
    Replies:
    0
    Views:
    779
    mesut
    Jun 29, 2007
  6. Douglas J. Badin

    &nbsp; is not generated for null values when using a format string

    Douglas J. Badin, Dec 2, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    288
    Jeffrey Tan[MSFT]
    Dec 4, 2003
  7. Tina

    &nbsp; and null fields in a datagrid

    Tina, Oct 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    426
    S.M. Altaf [MVP]
    Oct 19, 2005
  8. hotkitty

    Parsing CSV and "&nbsp;&nbsp;"

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