1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
string query = "UPDATE contact_associe SET nom_contact_associe = @nom_contact_associe,tel_contact_associe = @tel_contact_associe, mobile_contact_associe = @mobile_contact_associe, email_contact_associe = @email_contact_associe WHERE id_contact_associe = @id_contact_associe";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.Parameters.AddWithValue("@nom_contact_associe", (GridView1.Rows[e.RowIndex].FindControl("textNom_contact_associe") as TextBox).Text.Trim());
sqlCmd.Parameters.AddWithValue("@tel_contact_associe", (GridView1.Rows[e.RowIndex].FindControl("textTel_contact_associe") as TextBox).Text.Trim());
sqlCmd.Parameters.AddWithValue("@mobile_contact_associe", (GridView1.Rows[e.RowIndex].FindControl("textMobile_contact_associe") as TextBox).Text.Trim());
// sqlCmd.Parameters.AddWithValue("@fonction_contact_associe", (GridView1.Rows[e.RowIndex].FindControl("textFonction_contact_associe") as TextBox).Text.Trim());
sqlCmd.Parameters.AddWithValue("@email_contact_associe", (GridView1.Rows[e.RowIndex].FindControl("textEmail_contact_associe") as TextBox).Text.Trim());
sqlCmd.Parameters.AddWithValue("@id_contact_associe", Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()));
sqlCmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
PopulateGridView();
LabelSuccess.Text = "Modification réussie";
LabelError.Text = "";
}
}
catch (Exception ex)
{
LabelSuccess.Text = "";
LabelError.Text = ex.Message;
}
} |
Partager