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, if it makes any difference. Also,
the datagrid rows (items) are NOT EditItem type rows.

Any suggestion is greatly appreciated. I'm very desperate for an answer.

KD

RE: Urgent: How to NOT display "&nbsp;" in datagrid when NULL by Abhi

Abhi
Thu Jul 21 14:02:05 CDT 2005

Can you try using ISNULL function in the Database. Like if you are using the
Stored Procedure, use ISNULL for that particular column.

"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, if it makes any difference. Also,
> the datagrid rows (items) are NOT EditItem type rows.
>
> Any suggestion is greatly appreciated. I'm very desperate for an answer.
>
> KD
>
>

RE: Urgent: How to NOT display "&nbsp;" in datagrid when NULL by CalvinKD

CalvinKD
Thu Jul 21 19:39:06 CDT 2005

Hi Abhi,
Thanks for your post. Yes, I've tried that too and did not help. Datagrid
seems to interpret null or empty string "" the same and " " is displayed
unless I return the null value as an empty string with a space, " " rather
than "". But that's not good.
However, the following works fine but I'm just wondering if there's a better
way of doing it.
Datagrid_ItemDataBound ()
{
...
for (int i=0; i<e.Item.Cells.Count; i++)
{
if (e.Item.Cells[i] == null || e.Item.Cells[i].Text == " ")
e.Item.Cells[i].Text = "";
}
}


"Abhi" wrote:

> Can you try using ISNULL function in the Database. Like if you are using the
> Stored Procedure, use ISNULL for that particular column.
>
> "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, if it makes any difference. Also,
> > the datagrid rows (items) are NOT EditItem type rows.
> >
> > Any suggestion is greatly appreciated. I'm very desperate for an answer.
> >
> > KD
> >
> >