Вопрос

I'm using DevExpress GridView. I need to show the totals on last page only. So, I need to check if grid.PageIndex == grid.PageCount. But PageIndex is set to irrelevant random numbers (at least I didn't find any logic), and I don't know what's missing in my code.

 <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>

And code behind:

    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);
    }
Это было полезно?

Решение

This is how I fixed the problem, but still don't know why grid.PageIndex contained random values in the code above.

    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);
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top