Problem with empty cell value in GridView - DOTNET

This is a discussion on Problem with empty cell value in GridView - DOTNET ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Problem with empty cell value in GridView

  1. Default Problem with empty cell value in GridView

    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



  2. Default Re: Problem with empty cell value in GridView

    "Bill Gower" <billgower@charter.net> wrote in message
    news:O14dgSG2HHA.5884@TK2MSFTNGP02.phx.gbl...

    > 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


  3. Default Re: Problem with empty cell value in GridView

    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]" <mark@markNOSPAMrae.net> wrote in message
    news:%23rUmncG2HHA.3916@TK2MSFTNGP02.phx.gbl...
    > "Bill Gower" <billgower@charter.net> wrote in message
    > news:O14dgSG2HHA.5884@TK2MSFTNGP02.phx.gbl...
    >
    >> 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




  4. Default Re: Problem with empty cell value in GridView

    "Bill Gower" <billgower@charter.net> wrote in message
    news:u0ChG%23G2HHA.1212@TK2MSFTNGP05.phx.gbl...

    > 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


  5. Default Re: Problem with empty cell value in GridView

    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]" <mark@markNOSPAMrae.net> wrote in message
    news:OUmqpFH2HHA.5772@TK2MSFTNGP02.phx.gbl...
    > "Bill Gower" <billgower@charter.net> wrote in message
    > news:u0ChG%23G2HHA.1212@TK2MSFTNGP05.phx.gbl...
    >
    >> 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




  6. Default Re: Problem with empty cell value in GridView

    "Bill Gower" <billgower@charter.net> wrote in message
    news:%23liK7%23H2HHA.748@TK2MSFTNGP04.phx.gbl...

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

Similar Threads

  1. Getting value of a GridView cell
    By Application Development in forum CSharp
    Replies: 4
    Last Post: 11-16-2007, 05:11 PM
  2. Is there a way to format a cell in a GridView?
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 10-23-2007, 05:25 PM
  3. get cell value within gridview
    By Application Development in forum DOTNET
    Replies: 14
    Last Post: 10-18-2007, 01:18 PM
  4. Selected cell in Gridview
    By Application Development in forum DOTNET
    Replies: 2
    Last Post: 08-08-2007, 06:46 PM
  5. Gridview - Pull value from one cell in one row
    By Application Development in forum DOTNET
    Replies: 4
    Last Post: 08-05-2007, 01:47 PM