datagrid with no records - showing a line

Discussion in 'ASP .Net Datagrid Control' started by Tony Farrell, Feb 25, 2004.

  1. Tony Farrell

    Tony Farrell Guest

    Hi everyone,

    Using asp.net and a datagrid -

    When there are no records returned from
    the query - is there a way to add/insert
    a line into the grid stating there is/are
    no records to display???

    thanks
    tony
     
    Tony Farrell, Feb 25, 2004
    #1
    1. Advertising

  2. I've found the easiest way is after binding, check to see if there are no
    records returned. If not, hide the DataGrid and show a Label that says,
    "No records," or whatnot. If there are records, then do the opposite.

    That is, you might have something like:

    myDataGrid.DataSource = ...
    myDataGrid.DataBind()

    If myDataGrid.Items.Count = 0 then
    'There are no records
    myDataGrid.Visible = False
    someLabelWithAMessage.Visible = True
    Else
    myDataGrid.Visible = True
    someLabelWithAMessage.Visible = False
    End If


    Happy Programming!

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!



    "Tony Farrell" <> wrote in message
    news:...
    > Hi everyone,
    >
    > Using asp.net and a datagrid -
    >
    > When there are no records returned from
    > the query - is there a way to add/insert
    > a line into the grid stating there is/are
    > no records to display???
    >
    > thanks
    > tony
     
    Scott Mitchell [MVP], Feb 25, 2004
    #2
    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. Ray Booysen
    Replies:
    2
    Views:
    656
    Ray Booysen
    Mar 28, 2006
  2. Replies:
    1
    Views:
    408
    Aytaç ÖZAY
    Apr 10, 2006
  3. Luke Airig
    Replies:
    0
    Views:
    812
    Luke Airig
    Dec 31, 2003
  4. Burak
    Replies:
    1
    Views:
    100
    Scott Mitchell [MVP]
    May 18, 2004
  5. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    474
    Ray at
    May 10, 2004
Loading...

Share This Page