Habilite los campos IndexChanging, CancelilngEditing y RowUpdating, Al momento de dar clic sobre "Update" si muestra los labels y el texto en ellos pero cuandodoy en "Update" me tira una excepcion
Index was out of range. Must be non-negative and less than the size of the collection
Este es mi codigo
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
bool IsUpdated = false;
int ID = (int)GridView2.DataKeys[e.RowIndex].Value;
int PAYROLL = (int)GridView2.DataKeys[e.RowIndex].Value;
int POOL = (int)GridView2.DataKeys[e.RowIndex].Value;
int TEAM = (int)GridView2.DataKeys[e.RowIndex].Value;
int ROL = (int)GridView2.DataKeys[e.RowIndex].Value;
TextBox WHO = (TextBox)GridView2.Rows[e.RowIndex].FindControl("Tgv_who");
TextBox NAME = (TextBox)GridView2.Rows[e.RowIndex].FindControl("Tgv_name");
TextBox OU = (TextBox)GridView2.Rows[e.RowIndex].FindControl("Tgv_ou");
string myConnectionString = @"C:\\Users\\gutiece\\Desktop\\database\\" + "Database1.accdb";
using (OleDbConnection connection = new OleDbConnection())
{
using (OleDbCommand command = new OleDbCommand())
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
command.Connection = connection;
command.CommandText = "UPDATE users SET who = @who, payroll_number = @payroll, name = @name, ou = @ou, pool = @pool, team = @team, rol_id = @rol WHERE id = @id";
command.Parameters.AddWithValue("@id", ID);
command.Parameters.AddWithValue("@payroll", PAYROLL);
command.Parameters.AddWithValue("@pool", POOL);
command.Parameters.AddWithValue("@team", TEAM);
command.Parameters.AddWithValue("@rol", ROL);
command.Parameters.AddWithValue("@who", WHO);
command.Parameters.AddWithValue("@name", NAME);
command.Parameters.AddWithValue("@ou", OU);
connection.Open();
IsUpdated = command.ExecuteNonQuery() > 0;
GridView2.DataBind();
Response.Redirect("WebForm2.aspx");
connection.Close();
}
}
}