I have a grid with 500+ records. On the very first page, when I randomly select any item and clicks on edit it will work, but after paging to any page it gives me exception\[code\]> Index was out of range. Must be non-negative and less than the size of> the collection. Parameter name: index\[/code\]I have cross checked : Viewstate is enabled, grid is binding properly.Below are my code:\[code\]/// <summary>/// Returns a comman separated value of the id selected in the grid./// </summary>/// <param name="gv"></param>/// <param name="checkbox"></param>/// <returns></returns>public static string GetGridViewsSelectedRowValues(GridView gv, string checkbox){ var sb = new StringBuilder(); if(gv.Rows.Count>0) { foreach (GridViewRow row in gv.Rows) { var cbx = (CheckBox) row.FindControl(checkbox); if(cbx!=null && cbx.Checked) { var dataKey = gv.DataKeys[row.RowIndex]; if (dataKey != null) sb.Append(string.Format("{0},", dataKey.Value)); } } } return sb.ToString().Remove(sb.ToString().LastIndexOf(','));}\[/code\]My Edit Button clicked event: \[code\]protected void btnEdit_Click(object sender, EventArgs e){ int count = Common.GridSelectedRows(gvCityMaster, "chkBxSelect"); if (count > 1) { Common.ShowMessage("Only one item can be edited at once."); } else { int id = Common.ParseInt(Common.GetGridViewsSelectedRowValues(gvCityMaster, "chkBxSelect")); if (id > 0) { DisplayForm(); DisplayUserDetails(id); } }}\[/code\]I even looked into the DataKeys Collection, its coming 18 in each collection, which is fine.