Bonjour,

Je développe une application web en asp.net et c#. J'ai deux problèmes. Le premier que voici :

Sur ma page webForm.aspx j'ai mis un GridView dans lequel j'ai ajouté à sa déclaration OnRowUpdating = "GridView1_OnRowUpdating". Sur le fichier associé en .aspx.cs j'ai rempli tel quel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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;
            }
        }
Cependant lorsque je suis en train de modifier une ligne de mon gridView seul la méthods "GridView1_RowEditing" est prise en compte. C'est-à-dire qu'à aucun moment mon programme va lire la méthode "onRowUpdating" et je ne sais pas pourquoi... Des avis/conseils de résolutions ?

Second problème :

Toujours sur le gridView j'aimerai changé la longueur des cellules des colonnes mais je n'ai pas trouvé comment faire. De même tous conseils/avis sont bons à prendre.

Bien cordialement,