2015-11-09 70 views
0

我在更新面板中放置了兩個網格視圖。它們都允許分頁顯示數據。分頁更新面板裏面不工作

.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(); 
} 

頁面控件顯示的頁面數量,而是隻呈現第一頁。如果我點擊下一頁,它不會執行任何操作。

我錯過了什麼?

+0

如果您在分配頁面索引之前調用DoProcess()會發生什麼情況MembersGrid.PageIndex = e.NewPageIndex; – Bayeni

+0

更改了'PageIndexChanging'中的代碼序列,即首先調用DoProcess()。它會拋出一個錯誤'Sys.WebForms.PageRequestManagerParserErrorException:從服務器收到的消息無法解析。當我點擊下一頁時。 @Bayeni –

+1

將'!IsPostBack'內的'Page_Load'命名爲'DoProcess()'。 – Prabhat

回答

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

試試這個。

+0

刪除線,但沒有運氣。 :-( –