Index out of range, but why?

Posted by Stuart on Stack Overflow See other posts from Stack Overflow or by Stuart
Published on 2012-11-15T16:43:12Z Indexed on 2012/11/15 17:00 UTC
Read the original article Hit count: 171

Filed under:
|

I have a gridview, and i have a SelectedIndexChanged event on it...

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow Row = GridView1.SelectedRow;

    //do some stuff
}

Then i get an error...

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

I dont understand why, the Gridview is being binded in pageload. but not in post back...

if (!IsPostBack)
    {
        GridView1.DataSource = UserAccounts;
        GridView1.DataBind();
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET