0

Using ASP.NET, I created dynamic data folder using custom pages. The table in the DB that this folder refers to has 3 FK's, which appear as hyperlinks when viewed on screen inside the table (see below)

screenshot of DetailsView control

Take the first record for an example, When I click on 'thur 21st march' or '100' it will bring me to the corresponding page i.e the particular diary page or invoice page.

However problem being when I click on 'over there' to load the subcontractor page the application crashes at:

void DetailsView1_PreRender(object sender, EventArgs e)
{
    int rowCount = DetailsView1.Rows.Count;

    SetDelete(DetailsView1.Rows[rowCount - 1]);
}

The error is:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Konstantin
  • 796
  • 1
  • 11
  • 32
Mick
  • 183
  • 2
  • 3
  • 12
  • Your `DetailsView` has zero rows when you set rowCount there, so your (rowCount - 1) index is negative. That's what's causing the error. – Josh Darnell Mar 25 '13 at 14:53
  • I don't understand how does it have zero rows if it is displaying a sub contractor – Mick Mar 25 '13 at 15:31
  • I wonder if it's an issue with the order of the DataBinding? Call `DetailsView1.DataBind();` at the beginning of that _PreRender method to see if that's the issue. – Josh Darnell Mar 25 '13 at 17:47

0 Answers0