473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to display blank instead of   in BoundColumn if null

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

Nov 19 '05 #1
1 3726
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Kattke | last post by:
If I have created a DOM Doc with some randomly blank fields, what is the best way to test and using XSL, create normal tables with &nbsp; instead of blanks I've seen posts mentioning: <xsl:if/>...
12
by: Tjerk Wolterink | last post by:
In XHTML the entity nbsp stands for   A normal space like " " is also displayed as an normal space, but multiple spaces like " " are interpreted as 1 space in the xhtml page. So there comes...
5
by: Naveen K Kohli | last post by:
I am try to set the text of the drop down list item as ListItem li = new ListItem(); li.Text = "&nbsp;"+"MyValue"; myDropDown.Items.Add("li); The intent is to add a spacing in front of the...
2
by: Rob T | last post by:
I have a dropdown list that I would like to put in a bunch of &nbsp;'s into it (I'm setting the font to a monospace font so I can show a couple of columns nice and neat). In the old asp days, I...
1
by: Vikram | last post by:
i am adding a row in dataset , in which i want to add &nbsp; (space chracter for html) and then want to bind dataset to asp.net dropdown list box. But & automatically converted to &amp chracter....
5
by: Tim | last post by:
Hi, I am trying to load up a drop list with semi aligned columns like so: Item 2 Something Else etc. To do so, I have tried to fill the Text valus of ListItems like so:
3
by: yawnmoth | last post by:
<? echo 'a'.trim(html_entity_decode('&nbsp;a&nbsp;')).'a'; ?> Shouldn't PHP output aaa? Looking at the documentation for trim I see that it doesn't support chr(0xA0) (eg....
4
by: dennis.joseph | last post by:
Hello Everyone, I have scoured through a million messages (ok...thats a bit exaggerated) but I just cannot figure out how to display null values in a query. I have tried Nz, IIF, Count(*) but it...
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.