protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string username = GridView1.DataKeys[e.RowIndex].Values["Name"].ToString();//Index was out of range. Must be non-negative and less than the size of the collection Parameter name: index (this is error) TextBox Remarks = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtRemarks"); string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlCommand cmd = new SqlCommand("update gridsample set Remarks='" + Remarks.Text + "'where Name='" + username+"';", con); cmd.ExecuteNonQuery(); con.Close(); GridView1.EditIndex = -1; BindEmployeeDetails(); } }
<asp:GridView ID="GridView1" runat="server" DataKeyNames="Name" > </asp:GridView>
DataKeyNames="Name"
string username = GridView1.DataKeys[e.RowIndex].Value.ToString();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)