如何仅在最终页面上显示dx gridview total(摘要项目)?

时间:2013-08-18 14:09:39

标签: asp.net gridview devexpress

以下是我简化的gridview

目前,摘要显示在每个页面上。但客户只需要在最后一页上获得总数。 (或者甚至更好地在每页上显示“页面”的总量,以及最后一页上的所有页面的总数)。

非常感谢任何帮助:)

<dx:ASPxGridView ID="GrdMain" ClientInstanceName="GrdMain" runat="server" 
        KeyFieldName="AgentAccountSummaryId" Width="100%" AutoGenerateColumns="False">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="Debit" VisibleIndex="6" UnboundType="Decimal">
            <FooterCellStyle ForeColor="Brown" />
            <PropertiesTextEdit DisplayFormatString="c0" />
        </dx:GridViewDataTextColumn>
    </Columns>

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

更新:以下是我在Code中所做的所有事情(在Page_Load中):

GrdMain.SettingsPager.PageSize = 25;
GrdMain.ForceDataRowType(typeof(SomeTypeView));
GrdMain.DataSource = GetListOfSomeType();
GrdMain.DataBind();                

我还应该补充说我正在使用DevExpress GridView

1 个答案:

答案 0 :(得分:1)

ASPX页面:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
    AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" 
    ondatabound="GridView1_DataBound" PageSize="3" ShowFooter="True">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
            ReadOnly="True" SortExpression="id" />
        <asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
        <asp:BoundField DataField="vote" HeaderText="vote" SortExpression="vote" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ProjectDB %>" 
    onselected="SqlDataSource1_Selected" SelectCommand="SELECT * FROM [tblA]" >
</asp:SqlDataSource>

代码背后:

decimal RowCount;
protected void GridView1_DataBound(object sender, EventArgs e)
{
    int pageSize = GridView1.PageSize;
    decimal totalPages = Math.Ceiling(RowCount / pageSize);

    int TotalAllPage=0;
    int TotalPerPage=0;
    foreach (GridViewRow row in GridView1.Rows)
    {
        TotalPerPage += int.Parse( row.Cells[2].Text);
    }
    DataView dView = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    DataTable dTable = dView.ToTable();
    foreach (DataRow item in dTable.Rows)
    {
        TotalAllPage += int.Parse(item[2].ToString());
    }

    if (GridView1.PageIndex + 1 == totalPages)
    {
        GridView1.FooterRow.Cells[2].Text = "Total all page:" + TotalAllPage;
    }
    else
    {
        GridView1.FooterRow.Cells[2].Text = "Total this page:" + TotalPerPage;
    }
}
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
    RowCount = e.AffectedRows; 
}