Bonjour
J'ai commencé un projet asp ajax et j'ai un problémé que voici:
Jai mis une gridview dans un updatepanel et j'ai créé dynamiqquement deux triggers. Une pour insérer et une autre pour supprimer. Mais les deux événemens se déclanche à la fois du coup à chaque insertion je perds la première ligne de ma gridview.
Voici un peu de code pour vous donner une idée:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
            <ContentTemplate>
        <asp:SqlDataSource ID="sdsMarche" runat="server" ConnectionString="<%$ ConnectionStrings:cnsEcheance %>"
            SelectCommand="SELECT * FROM [tblMarche]"></asp:SqlDataSource>
        <asp:GridView ID="grvMarche" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            BorderColor="#7EACB1" DataSourceID="sdsMarche" ShowFooter="True" BorderStyle="Solid" BorderWidth="1px">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="imgSupp" runat="server" ImageUrl="~/images/IconeSupp.gif" OnClick="imgSupp_Click" />
                        <asp:HiddenField ID="hdfNumMarche" runat="server" Value='<%# Eval("NumMarche") %>' />
                    </ItemTemplate>
                    <FooterTemplate><asp:Image ID="imgSupp" runat="server" ImageUrl="~/images/icon_annule.gif" style="cursor: hand" />
                        <asp:HiddenField ID="hdfNumMarche" runat="server" Value='-1' />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Nom" SortExpression="Nom">
                    <FooterTemplate>
                        <asp:TextBox ID="txtCode" runat="server" Width="72px" BackColor="Transparent" BorderStyle="None"></asp:TextBox>&nbsp;
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="txtCode" runat="server" Text='<%# Bind("Nom") %>' Width="72px" BackColor="Transparent" BorderStyle="None"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Localisation" SortExpression="Localisation">
                    <EditItemTemplate>
                        &nbsp;
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="txtLib" runat="server" Text='<%# Bind("Localisation") %>' Width="320px" BackColor="Transparent" BorderStyle="None"></asp:TextBox>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtLib" runat="server" Width="320px" BackColor="Transparent" BorderStyle="None" OnTextChanged="txtLib_TextChanged"></asp:TextBox>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
            <RowStyle BorderStyle="Double" BorderColor="#C2D8DA" BorderWidth="1px" HorizontalAlign="Center" VerticalAlign="Middle" />
            <EmptyDataTemplate>
                <table cellpadding="0" cellspacing="0" style="width: 1px; height: 1px;">
                    <tr>
                        <td class="grvHeader" headers="th_Code" style="width: 2730px; height: 34px">
                        </td>
                        <td class="grvHeader" style="width: 42px; height: 34px" headers="th_Code">
                            Code</td>
                        <td class="grvHeader" style="height: 34px" headers="th_Etat">
                            Etat</td>
                    </tr>
                    <tr>
                        <td class="grvLingne" style="width: 2730px; height: 3px" valign="top">
                            <asp:Image ID="imgSupp" runat="server" ImageUrl="~/images/icon_annule.gif" style="cursor: hand" /></td>
                        <td class="grvLingne" style="width: 42px; height: 3px;" valign="top">
                            <asp:HiddenField ID="hdfNumMarche" runat="server" Value="-1" />
                            <asp:TextBox ID="txtCode" runat="server" Width="72px" BackColor="Transparent" BorderStyle="None"></asp:TextBox>
                </td>
                        <td class="grvLingne" style="height: 3px" valign="top">
                            <asp:TextBox ID="txtLib" runat="server" Width="320px" BackColor="Transparent" BorderStyle="None"></asp:TextBox></td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <HeaderStyle CssClass="grvHeader" HorizontalAlign="Center" VerticalAlign="Middle" BorderStyle="Solid" Font-Bold="False" />
            <FooterStyle BorderColor="#C2D8DA" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
                VerticalAlign="Middle" />
            <PagerStyle CssClass="grvHeader" />
        </asp:GridView>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ScriptManager1" EventName="ResolveScriptReference" />
            </Triggers>
        </asp:UpdatePanel>
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
30
31
32
33
34
35
36
37
38
39
40
41
42
  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvMarche.RowDataBound
        Dim trigger As AsyncPostBackTrigger = New AsyncPostBackTrigger()
 
        If (e.Row.RowType = DataControlRowType.Footer) Or (e.Row.RowType = DataControlRowType.EmptyDataRow) Then
            Dim txtLib As TextBox = CType(e.Row.FindControl("txtLib"), TextBox)
            trigger.ControlID = txtLib.UniqueID
            trigger.EventName = "TextChanged"
            UpdatePanel1.Triggers.Add(trigger)
        End If
 
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim txtCode As TextBox = CType(e.Row.FindControl("txtCode"), TextBox)
            Dim txtLib As TextBox = CType(e.Row.FindControl("txtLib"), TextBox)
            Dim imgSupp As ImageButton = CType(e.Row.FindControl("imgSupp"), ImageButton)
            txtCode.Attributes.Add("onkeyup", "Enregistrement('SaveMarche.aspx',document.getElementById('" & e.Row.ClientID & "'));")
            txtLib.Attributes.Add("onkeyup", "Enregistrement('SaveMarche.aspx',document.getElementById('" & e.Row.ClientID & "'));")
            trigger.ControlID = imgSupp.UniqueID
            trigger.EventName = "Click"
            'UpdatePanel1.Triggers.Add(trigger)
        End If
    End Sub
 
    Protected Sub imgSupp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Dim da As New dstParametreTableAdapters.QueriesTableAdapter
        Dim img As ImageButton = sender
        Dim rw As GridViewRow = DirectCast(img.NamingContainer, GridViewRow)
        Dim vNum As Integer = CInt(CType(rw.FindControl("hdfNumMarche"), HiddenField).Value)
        da.qsuppMarche(vNum)
        grvMarche.DataBind()
        UpdatePanel1.Update()
    End Sub
 
    Protected Sub txtLib_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim da As New dstParametreTableAdapters.QueriesTableAdapter
        Dim txt As TextBox = sender
        Dim rw As GridViewRow = DirectCast(txt.NamingContainer, GridViewRow)
        Dim vNom As String = CType(rw.FindControl("txtCode"), TextBox).Text
        Dim vlocalisation As String = CType(rw.FindControl("txtLib"), TextBox).Text
        da.qappMarche(vNom, vlocalisation)
        grvMarche.DataBind()
        UpdatePanel1.Update()
    End Sub
C'est à ne rien comprendre.
Je compte sur vous.