how to check if cell of gridview is empty?

Discussion in 'ASP .Net' started by Bart, Feb 8, 2008.

  1. Bart

    Bart Guest

    Hi,

    i need to check wether a cell of a gridview is empty or not. I did this:

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
    As System.EventArgs) Handles GridView1.SelectedIndexChanged
    Dim log1 As String
    log1 = GridView1.SelectedRow.Cells(1).Text
    .....

    If log1 = "" Then
    Response.Write("empty")
    else
    Response.Write(log1)
    end if
    ....


    When log1 contains data, i get it in the response.write, but when the field
    in the sql-database contains NULL or is empty (e.g. by a previous update
    operation), i don't get the expected 'empty'. So log1 = "" is considered
    as false.

    I checked the length with this line: response.write(log1.length)

    This gives the right length when data is present, but gives 6 when it's NULL
    or empty !!

    Is that the default length of the empty cell in a gridview? How to test when
    that cell is empty? (i also tried with IsDbNull but doesn't work either).

    Thanks
    Bart
     
    Bart, Feb 8, 2008
    #1
    1. Advertising

  2. "Bart" <> wrote in message
    news:...

    > How to test when that cell is empty?


    A quick View Source would have given you the answer...

    When a bound GridView cell contains no data, ASP.NET fills it with &nbsp;

    Hence the length of 6...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Feb 8, 2008
    #2
    1. Advertising

  3. Bart

    Bart Guest

    Thanks

    "Mark Rae [MVP]" <> schreef in bericht
    news:%...
    > "Bart" <> wrote in message
    > news:...
    >
    >> How to test when that cell is empty?

    >
    > A quick View Source would have given you the answer...
    >
    > When a bound GridView cell contains no data, ASP.NET fills it with &nbsp;
    >
    > Hence the length of 6...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Bart, Feb 8, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.rcn.com
    Replies:
    1
    Views:
    9,680
    Chris Smith
    Jul 12, 2004
  2. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    579
    Dave Thompson
    Feb 14, 2004
  3. Bill Gower

    Problem with empty cell value in GridView

    Bill Gower, Aug 6, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    1,034
    Mark Rae [MVP]
    Aug 7, 2007
  4. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    check for if a gridview is empty

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Aug 29, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    861
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
    Aug 30, 2007
  5. Savvoulidis Iordanis

    Empty gridview cells and checking for empty string

    Savvoulidis Iordanis, Sep 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    525
    Savvoulidis Iordanis
    Sep 5, 2008
Loading...

Share This Page