如何在UpdatePanel中更新GridView?

时间:2012-02-07 16:56:42

标签: gridview updatepanel

我有一个多页面gridview,调用gvChild,它位于UpdatePanel内。

问题是当我从第1页到第2页时,当我选择gvChild的一行时,该值不会更新。实际上我正在使用'row'来保存GridView中的'store'信息,当我点击其中一个'行'时,gvChild.SelectedDataKey将会更新。但是,当我点击第二页上的行时,SelectedDataKey只有'null',这很棘手......

所以我正在考虑在gridview页面发生变化时如何更新我的UpdatePanel。我搜索了谷歌,并试图为我的gridview-'gvChild添加一个触发器,并将EventName设置为“PageIndexChanging”,但它不起作用。非常感谢!

<asp:UpdatePanel ID="upnlChild" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
        <div>
            <div class="grid">
                <div class="rounded">

                    <div class="mid-outer">
                        <div class="mid-inner">
                            <div class="mid">
                                <asp:GridView SkinID="mastertable" ID="gvChild" runat="server" OnRowDataBound="gvChild_RowDataBound"
                                    OnRowCommand="gvChild_RowCommand" DataKeyNames="StoreID" OnSelectedIndexChanged="gvChild_SelectedIndexChanged"
                                    OnPageIndexChanging="gvChild_PageIndexChanging" OnSorting="gvChild_Sorting">
                                    <Columns>
                                        <asp:BoundField HeaderText="&nbsp;ID" DataField="StoreID" SortExpression="StoreID"
                                            ItemStyle-CssClass="first">
                                            <ItemStyle CssClass="first"></ItemStyle>
                                        </asp:BoundField>
                                        <asp:BoundField HeaderText="Store #" DataField="StoreNum" SortExpression="StoreNum" />

                                    </Columns>
                                    <PagerTemplate>
                                        <div class="pager">
                                            <asp:ImageButton CommandName="Page" SkinID="first" CommandArgument="first" ID="btnChild_First"
                                                runat="server" CausesValidation="false" />
                                            <asp:ImageButton CommandName="Page" SkinID="prev" CommandArgument="prev" ID="btnChild_Prev"
                                                runat="server" CausesValidation="false" />
                                            <asp:Label ID="lblPage" runat="server" Text="Page"></asp:Label>
                                            <asp:DropDownList ID="ddlChild_Pages" runat="server" OnSelectedIndexChanged="ddlChild_Pages_SelectedIndexChanged"
                                                AutoPostBack="True">
                                            </asp:DropDownList>
                                            <asp:Label ID="lblPageCount_Child" runat="server"></asp:Label>
                                            <asp:ImageButton CommandName="Page" SkinID="next" CommandArgument="next" ID="btnChild_Next"
                                                runat="server" CausesValidation="false" />
                                            <asp:ImageButton CommandName="Page" SkinID="last" CommandArgument="last" ID="btnChild_Last"
                                                runat="server" CausesValidation="false" /></div>
                                    </PagerTemplate>
                                </asp:GridView>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <asp:Button ID="btnChild_Add" runat="server" Text="Add Store" OnClick="btnChild_Add_Click"
            CausesValidation="false" />
    </ContentTemplate>

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="gvChild" EventName="PageIndexChanging" />
    </Triggers>

</asp:UpdatePanel>

0 个答案:

没有答案