bonjour tout le monde j'espère que vous allez m'aidé à résoudre mon problème qui consiste en fait de récupérer une valeur d'un champ lors d'une opération de modification faite sur une GridView !! même l'ancienne valeur ne marche pas !!
je vous donne le code de ma gridView :
mon datasource je le gère seul dans ma page aspx.cs donc je dois tout gèrer seul (c'est un peu galère mais c'est pas un choix )!!! alors voici ce que j'ai mis dans ma page aspx.cs pour l'update :
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 <asp:GridView ID="GridView1" AutoGenerateColumns ="False" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames ="Id_AgoraClaim,Id_ClaimType,num_goodwill" AllowPaging="True" GridLines="Vertical" PageSize ="1" OnRowUpdating ="GridView1_Updating" OnPageIndexChanging ="GridView1_PageIndexChanging" OnRowCancelingEdit ="GridView_CancelingEdit" OnRowEditing ="GridView1_Editing" AllowSorting ="True" OnSorting ="GridView1_Sorting" emptydatatext="Pas d'interventions en attente."> <Columns> <asp:CommandField ShowEditButton ="True" /> <asp:BoundField DataField ="code_garantie" HeaderText ="Code garantie" ReadOnly="True"/> <asp:BoundField DataField ="num_goodwill" HeaderText ="Goodwill" /> <asp:TemplateField HeaderText ="GoodWill"> <ItemTemplate> <asp:Label runat="server" ID="num" Text='<%#Eval("num_goodwill") %>' /> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" id="Textnum" Text ='<%#Eval ("num_goodwill") %>' /> <asp:RequiredFieldValidator runat="server" ID ="Valnum_goodwill" ControlToValidate="Textnum" ValidationGroup="var1" ErrorMessage ="*" /> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
si vous avez remarqué dans ma gridView j'ai deux fois le champ GoodWill la 1er sous forma de asp:BoundField la 2ème sous forma de Template !! et ça pour tester les deux cas !!!dans le code behind !! et quand je débug j'ai 0 dans le f, 0 dans k et 0 dans h !!!!!! avez vous une idée svp merci
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 protected void GridView1_Updating(object sender, GridViewUpdateEventArgs e) { int rownum = e.RowIndex; TextBox LastName = GridView1.Rows[e.RowIndex].FindControl("Textnum") as TextBox ; int f = Convert.ToInt32(LastName .Text); int k = Convert.ToInt32(e.NewValues[GridView1.DataKeyNames[2]]); int h = Convert.ToInt32(e.OldValues [GridView1.DataKeyNames[2]]); int j = Convert.ToInt32(GridView1.DataKeys[rownum][GridView1.DataKeyNames[0]]); int i = Convert .ToInt32 (GridView1 .DataKeys [e.RowIndex ]["Id_ClaimType"]); ClaimTypeBLL ClaimT = new ClaimTypeBLL (); ClaimT.UpdateClaimType_goodwill(j, i, k); GridView1.EditIndex = -1; GridView1.DataSource = ClaimT.GetClaimTypeNonValide(); GridView1.DataBind(); }
Partager