473,378 Members | 1,456 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,378 software developers and data experts.

OnRowDataBound question

Hello,
I have run into an issue when using the OnRowDataBound event to apply
conditional formatting to a row. I need to check a specific column to see if
the value from the database is null. Without conditional formatting the page
just shows empty text in the table when the database column is null. I
figured the text value would be equivalent to "" but that doesn't work. Here
is a code snippet:

Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text = "blank"
End If
End Sub

This does not work - the text on the page always displays empty, it never
shows "blank". Am I missing something obvious? Is there a way to do this
using code similar to what I have above, or do I need to use a template
column along with a label control?

Thanks,
John
Aug 31 '06 #1
2 1564
John,

Why don't you set a breakpoint and check the value of the Text property?

Likely, an empty cell is rendered with a non-breaking space character. You
can either check on it, or try to trim it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Aconquija" <Ac*******@discussions.microsoft.comwrote in message
news:71**********************************@microsof t.com...
Hello,
I have run into an issue when using the OnRowDataBound event to apply
conditional formatting to a row. I need to check a specific column to see
if
the value from the database is null. Without conditional formatting the
page
just shows empty text in the table when the database column is null. I
figured the text value would be equivalent to "" but that doesn't work.
Here
is a code snippet:

Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text =
"blank"
End If
End Sub

This does not work - the text on the page always displays empty, it never
shows "blank". Am I missing something obvious? Is there a way to do this
using code similar to what I have above, or do I need to use a template
column along with a label control?

Thanks,
John

Aug 31 '06 #2
Thanks for the suggestion. I had actually tried something similar, and was
confused because I was seeing a whitespace as the value. But your suggestions
gave me an idea - I checked for a text value of in my code and it worked:

If e.Row.Cells(10).Text = " " Then e.Row.Cells(10).Text = "blank"

So I guess that the text value is of the row is the value that gets passed
into the HTML code between the <tdtags, and isn't representative of the
actual null value in the dataset cell.

Am I on the right track?
Thanks,
John

"Eliyahu Goldin" wrote:
John,

Why don't you set a breakpoint and check the value of the Text property?

Likely, an empty cell is rendered with a non-breaking space character. You
can either check on it, or try to trim it.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Aconquija" <Ac*******@discussions.microsoft.comwrote in message
news:71**********************************@microsof t.com...
Hello,
I have run into an issue when using the OnRowDataBound event to apply
conditional formatting to a row. I need to check a specific column to see
if
the value from the database is null. Without conditional formatting the
page
just shows empty text in the table when the database column is null. I
figured the text value would be equivalent to "" but that doesn't work.
Here
is a code snippet:

Protected Sub Grid_Databound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(10).Text = "" Then e.Row.Cells(10).Text =
"blank"
End If
End Sub

This does not work - the text on the page always displays empty, it never
shows "blank". Am I missing something obvious? Is there a way to do this
using code similar to what I have above, or do I need to use a template
column along with a label control?

Thanks,
John


Aug 31 '06 #3

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
3
by: Elmo Watson | last post by:
I previously had a project working, in which the Gridview was populated by a DataSet - then, with a DropDownlist in one of the columns, using the OnrowDataBound event, to populate the DDL with the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...

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.