protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); string sqlQuery = "Update mytable set ID = @ID WHERE No ="+ index; GridOpen(sqlQuery); } void GridOpen(string send) { string con = "conn string"; using (SqlConnection dataConnection = new SqlConnection(con)) { using (SqlCommand dataCommand = new SqlCommand(send, dataConnection)) { int ld = 121; dataCommand.Parameters.AddWithValue("ID", ld); dataConnection.Open(); dataCommand.ExecuteNonQuery(); dataConnection.Close(); } } }