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