Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with empty cell value in GridView

Reply
Thread Tools

Problem with empty cell value in GridView

 
 
Bill Gower
Guest
Posts: n/a
 
      08-06-2007
I have an cell which contains a field member which is filled with
String.Empty. When I retrieve the value in the cell with
Cells[0].Text.ToString() and try to compare it to String.Empty, I can't
because it contains "&nbsp". I really don't want to compare the value to
that so how can I retrieve an empty cell so that it is String.Empty.

Bill


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-06-2007
"Bill Gower" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I have an cell which contains a field member which is filled with
> String.Empty. When I retrieve the value in the cell with
> Cells[0].Text.ToString() and try to compare it to String.Empty, I can't
> because it contains "&nbsp".


Yes - that's how empty GridView cells are rendered in HTML. A GridView is
nothing more than an HTML table by the time ASP.NET has rendered it to the
client browser - the rows are <tr> elements and the individual cells are
<td> elements. Some browsers have problems displaying <td> elements which
are completely empty, specifically with regard to borders etc, so ASP.NET
inserts &nbsp; to prevent this.

> I really don't want to compare the value to that


??? Why on earth not?

if (Cells[0].Text.ToString() == "&nbsp;")
{
// do something
}

What could be simpler...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
Bill Gower
Guest
Posts: n/a
 
      08-06-2007
Ok that's fine. I won't make it more difficult then it is. But now I do
have a real problem. I am retrieving the 3rd row which happens to have no
value in the cell and it is actually containing the value from the first row
same cell. When the gridview is displayed it is an empty cell but when I
retrieve it by

GridView.Rows[index].Cells[0].Text.ToString().

It has the value of the cell from the first row.

What is happening here?

Bill

"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "Bill Gower" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> I have an cell which contains a field member which is filled with
>> String.Empty. When I retrieve the value in the cell with
>> Cells[0].Text.ToString() and try to compare it to String.Empty, I can't
>> because it contains "&nbsp".

>
> Yes - that's how empty GridView cells are rendered in HTML. A GridView is
> nothing more than an HTML table by the time ASP.NET has rendered it to the
> client browser - the rows are <tr> elements and the individual cells are
> <td> elements. Some browsers have problems displaying <td> elements which
> are completely empty, specifically with regard to borders etc, so ASP.NET
> inserts &nbsp; to prevent this.
>
>> I really don't want to compare the value to that

>
> ??? Why on earth not?
>
> if (Cells[0].Text.ToString() == "&nbsp;")
> {
> // do something
> }
>
> What could be simpler...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-06-2007
"Bill Gower" <(E-Mail Removed)> wrote in message
news:u0ChG%(E-Mail Removed)...

> Ok that's fine. I won't make it more difficult then it is. But now I
> do have a real problem. I am retrieving the 3rd row which happens to have
> no value in the cell and it is actually containing the value from the
> first row same cell. When the gridview is displayed it is an empty cell
> but when I retrieve it by
>
> GridView.Rows[index].Cells[0].Text.ToString().
>
> It has the value of the cell from the first row.
>
> What is happening here?


Difficult to tell without seeing your code but, if you do a View Source on
the page in question, you will see the HTML table rendered from the GridView
webcontrol - does that shed any light on it...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Bill Gower
Guest
Posts: n/a
 
      08-06-2007
I checked the source and rows 1 to 3 have an entry in the cell and rows 4
to 5 have &nbsp in the cell. When I step through the code and check the
value at the cell from row 4, it has the value from the cell in row 1.

Bill


"Mark Rae [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bill Gower" <(E-Mail Removed)> wrote in message
> news:u0ChG%(E-Mail Removed)...
>
>> Ok that's fine. I won't make it more difficult then it is. But now I
>> do have a real problem. I am retrieving the 3rd row which happens to
>> have no value in the cell and it is actually containing the value from
>> the first row same cell. When the gridview is displayed it is an empty
>> cell but when I retrieve it by
>>
>> GridView.Rows[index].Cells[0].Text.ToString().
>>
>> It has the value of the cell from the first row.
>>
>> What is happening here?

>
> Difficult to tell without seeing your code but, if you do a View Source on
> the page in question, you will see the HTML table rendered from the
> GridView webcontrol - does that shed any light on it...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      08-07-2007
"Bill Gower" <(E-Mail Removed)> wrote in message
news:%23liK7%(E-Mail Removed)...

>I checked the source and rows 1 to 3 have an entry in the cell and rows 4
>to 5 have &nbsp in the cell. When I step through the code and check the
>value at the cell from row 4, it has the value from the cell in row 1.


Please show the code you're using...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty gridview cells and checking for empty string Savvoulidis Iordanis ASP .Net 1 09-05-2008 06:15 AM
how to check if cell of gridview is empty? Bart ASP .Net 2 02-08-2008 11:03 PM
Seting the drop down list with empty value in gridview tinique@gmail.com ASP .Net 0 11-28-2007 04:47 AM
How to set cell background based on cell value when datagrid is displayed RJ ASP .Net Datagrid Control 1 02-17-2005 09:37 PM
moving to cell Y if cell X has value Z. Clarke Rice Computer Support 0 06-30-2003 09:35 AM



Advertisments