E
Elroyskimms
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?
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?