I want that when a user presses select from the gridview to redirect him to a site, and the site parameter to be taken from the first row of gridview. I have this code, but I get the following error:
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
string strCell = row.Cells[1].Text;
string myPageUrl = "Meci.aspx?ID=" + strCell;
Response.Redirect(myPageUrl);
}
Please tell me how to fix the error or what other code to use!
It is different than What is an "index out of range" exception, and how do I fix it? because the answer there is that the index value is not correct, but I tried with other values (0,1,2.3,4,5 ...) but this error keeps coming every time. Randul este cel selectat, iar celula 1 exista si are o valoare, mai mult de atat ieri mi-a mers codul respectiv pe aceliasi pagina si acelasi gidview!