I have a gridview that pulls data from local SQL server. I chose 3 columns to be displayed on the gridview. I added a fourth column (select command). I would like to get the data from the first column which is an id when I click the select command but i always get an 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."
Basically I would like to get the id from the first column then assign it to a session variable then redirect to a second page and then use the content of that session variable to populate another textbox.
protected void grdClients_RowCommand(object sender, GridViewCommandEventArgs e)
{
string id = grdClients.Rows[grdClients.SelectedIndex].Cells[0].Text.ToString();
Session["ID"] = id;
Response.Redirect("secondPage.aspx");
}
Any suggestions?
Thanks