2013-08-19 66 views
0

我正在使用DevExpress GridView。我只需要在最後一頁顯示總計。所以,我需要檢查grid.PageIndex == grid.PageCount。但PageIndex被設置爲不相關的隨機數字(至少我沒有找到任何邏輯),我不知道我的代碼中缺少什麼。Devexpress GridView.PageIndex值有誤

<dx:ASPxGridView ID="GrdMain" ClientInstanceName="GrdMain" runat="server" 
     KeyFieldName="SomeId" Width="100%" AutoGenerateColumns="False"> 
<Columns> 
    <dx:GridViewDataTextColumn FieldName="Debit" VisibleIndex="6" UnboundType="Decimal"> 
    </dx:GridViewDataTextColumn> 
</Columns> 

<Settings ShowFooter="True" /> 
<TotalSummary> 
    <dx:ASPxSummaryItem FieldName="Debit" SummaryType="Sum"/> 
</TotalSummary> 

而後面的代碼:

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      grid.SettingsPager.PageSize = 25; 
      grid.ForceDataRowType(typeof(SomeTypeView)); 
     } 
     SetGridDataSource(); 
    } 

    private void SetGridDataSource() 
    { 
     grid.DataSource = GetListOfSomeType(); 
     grid.DataBind(); 
     grid.Settings.ShowFooter = (grid.PageIndex == grid.PageCount - 1); 
    } 

回答

0

這是我如何解決了這一問題,但仍然不知道爲什麼grid.PageIndex包含隨機值在上面的代碼。

private void SetGridDataSource() 
    {       
     grid.DataSource = GetListOfSomeType(); 
     grid.DataBind(); 

     grid.PageIndexChanged += new EventHandler(grid_PageIndexChanged); 
    } 

    void grid_PageIndexChanged(object sender, EventArgs e) 
    { 
     grid.Settings.ShowFooter = (grid.PageIndex == grid.PageCount - 1); 
    }