Server Error in '/GridView' Application. -------------------------------------------------------------------------------- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source Error: Line 128: //string currentExtension; Line 129: Line 130: Id = Convert.ToInt32(GridView1.DataKeys[1].Value); Line 131: Line 132: //currentTitleOfCourtesy = ((TextBox)r.FindControl("TitleOfCourtesyTextBox")).Text; Source File: e:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\WebSites\Subbu\SelectEdit\GridView\Edti3.aspx.cs Line: 130 Stack Trace:
It seems like the DataKeys collection is empty.
DataKeys
Try to change your code to something like:
if (GridView1 != null && GridView1.DataKeys.Count > 1) { Id = Convert.ToInt32(GridView1.DataKeys[1].Value); }
Id = Convert.ToInt32(GridView1.DataKeys[1].Value);
Id = Convert.ToInt32(GridView1.DataKeys[0].Value);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)