DataGrid Row Numbering On Empty Reader

Discussion in 'ASP .Net Web Controls' started by Elroyskimms, Aug 11, 2005.

  1. Elroyskimms

    Elroyskimms Guest

    I have a DataGrid and the first column is a template column which
    displays 1 for the first row, 2 for the second row, 3 for the third
    row, and so on. I accomplish this by using the following tag inside the
    template column:

    <%# Container.ItemIndex + 1 %>

    If the DataSource is a datareader with at least one record, everything
    works great. If the DataSource returns a datareader that has no rows,
    the DataBind command errors out, claiming that it is trying to access a
    reader that is closed. Apparently the ItemIndex property is still being
    accessed (or at least trying to be accessed) even though the datareader
    is empty (not closed, just empty).

    If I remove the "numbering" template column, the problem goes away. If
    I trap the DataBind line of code within a Try Catch block, the problem
    goes away. Is there a way to accomplish the "numbering" column in a
    datagrid that can also gracefully handle an empty datareader?
     
    Elroyskimms, Aug 11, 2005
    #1
    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. buran

    numbering rows in datagrid

    buran, Jul 7, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    475
    Saravana
    Jul 7, 2003
  2. buran

    numbering rows in datagrid

    buran, Oct 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    527
    Cowboy \(Gregory A. Beamer\)
    Oct 15, 2003
  3. =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=

    change row color of empty row

    =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?=, Oct 19, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    452
    Walter Wang [MSFT]
    Oct 24, 2006
  4. Guilherme Grillo

    reader inside a reader

    Guilherme Grillo, Nov 7, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    534
    sloan
    Nov 7, 2007
  5. Pokkai Dokkai
    Replies:
    1
    Views:
    241
    Hassan Schroeder
    Mar 24, 2008
Loading...

Share This Page