分页不在gridview indside更新面板中工作

时间:2015-11-09 11:41:58

标签: c# asp.net gridview data-paging

我在更新面板中放置了两个网格视图。它们都允许分页显示数据。

我的.aspx页面代码是:

<asp:UpdatePanel ID="upMaster" runat="server" >
     <ContentTemplate>
        <div class="TeamBox">
            <asp:GridView ID="MangersGrid" GridLines="None" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" runat="server" OnPageIndexChanging="MangersGrid_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="Team Managers" />
                </Columns>
            </asp:GridView>
        </div>

        <div class="TeamBox">
            <asp:GridView ID="MembersGrid" AllowPaging="true" GridLines="None" AutoGenerateColumns="false" runat="server" PageSize="10" OnPageIndexChanging="MembersGrid_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="Team Members" />
                </Columns>
            </asp:GridView>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

.cs的代码是:

protected void Page_Load(object sender, EventArgs e) {   
    DoProcess();
}
void DoProcess() {
    // logic to get data table records one for each.
    MangersGrid.DataSource = dtManagers;
    MangersGrid.DataBind();
    MembersGrid.DataSource = dtNativeMembers;
    MembersGrid.DataBind();
    upMaster.Update();
}
void MangersGrid_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
    MangersGrid.PageIndex = e.NewPageIndex;
    DoProcess();
}
// Members Gridview page index change event
void MembersGrid_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
    MembersGrid.PageIndex = e.NewPageIndex;
    DoProcess();
}

页面控件显示页数,但只显示第一页。如果我点击下一页,它什么都不做。

我错过了什么?

1 个答案:

答案 0 :(得分:0)

void DoProcess() {
   MangersGrid.DataSource = dtManagers;
   MangersGrid.DataBind();
   MembersGrid.DataSource = dtNativeMembers;
   MembersGrid.DataBind();
   //upMaster.Update(); <-- remove this line
}

试试这个。