473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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().Tri m() == System.DBNull.V alue.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 3774
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().Tri m() == System.DBNull.V alue.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
1585
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/>   translate() And the most informative one was Listed as: (but I'm still a little unclear)
12
6036
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 the &nbsp; in handy: with "&nbsp;&nbsp;" you have two spaces. So with the nbsp entity you can create multiple spaces (in the display). Now i have an xml file with &nbsp; entities, i put it in an xsl-file that know xhtml entities.
5
11209
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 text. Its not doing what I am trying to do. The text shows up as "&ampMyValue"
2
1986
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 had no problem doing this, but now if I try to do something like this... boxOption.Items.Add(New ListItem("myFirstCol&nbsp;&nbsp;&nbsp;myLastCol")) ....it converts each & to a &amp;
1
1746
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. Is there any way by which &nbsp; can be retained as it is when dropdown throws the html part. THanks
5
1706
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
8944
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. html_entity_decode('&nbsp;')), but it seems to me like it ought to...
4
7309
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 just does not work. I hope someone can help me with this. Here are the details: Table: Group Fields: Group Name, Group ID Table: Region
28
13207
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 yow But, in firefox, for same html, getting this:
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.