如何在Gridview中添加页脚 [英] How Can I Add Footer In Gridview

查看:198
本文介绍了如何在Gridview中添加页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用Telerik。

我想在Gridview底部添加Footer,以便显示该列属性的总计。



我在Windows窗体上工作。

代码如下。



GridViewSummaryItem summaryItem = new GridViewSummaryItem();

summaryItem.Name =Units ;

summaryItem.Aggregate = GridAggregateFunction.Count;



GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();

summaryRowItem.Add(summaryItem);



this.GridViewWorkInProgress.SummaryRowsBottom.Add(summaryRowItem);





这是我添加的代码,但它不会在底部包含页脚。





它会显示错误空引用异常未处理。

Hello,
I am working on Telerik.
I want to add Footer at bottom of Gridview so it can show the totals for that column's property.

I m work on Windows form.
Code is below.

GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Units";
summaryItem.Aggregate = GridAggregateFunction.Count;

GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);

this.GridViewWorkInProgress.SummaryRowsBottom.Add(summaryRowItem);


thats code i added but it will not include footer at bottom.


it will shows error of Null reference Exception unhandled.

推荐答案

Telerik RadGrid provides a method to define aggregates on a per column basis from design time and render the results inside the respective column's footer. Aggregate calculations are supported for GridBoundColumns and GridCalculatedColumns.

Steps:-

--Subscribe to the your DataBound event of Grid
--Iterate through the rows in the underlying grid source
--Sum up the total and insert it in the respective column footer

aspx-

<telerik:RadGrid ID="RG1" runat="server">
  <MasterTableView AutoGenerateColumns="False" ShowFooter="True" AllowPaging="true">
    <FooterStyle BackColor="#cc6633"></FooterStyle>
    <Columns>
      <telerik:GridBoundColumn HeaderText="Item Count" DataField="Item Count" UniqueName="Item Count" />
    </Columns>
  </MasterTableView>
  <PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>

in C#-

private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        int fieldValue = int.Parse(dataItem["Item Count"].Text);
        total = total + fieldValue;
    }
    if (e.Item is GridFooterItem)
    {
        GridFooterItem footerItem = (GridFooterItem)e.Item;
        footerItem["Item Count"].Text = "Total: " + total.ToString();
    }
}

protected void RadGrid1_DataBound(object sender, System.EventArgs e)
{
    DataTable gridTable = GetDataTable("SELECT * FROM [Order Details]");

    foreach (DataRow row in gridTable.Rows)
    {
        grandTotal = grandTotal + int.Parse(row["Quantity"]);
    }
    GridFooterItem footerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
    footerItem["Item Count"].Text = footerItem["Item Count"].Text + "<br> Total for all pages: " + grandTotal.ToString();
}


请参阅此处的参考资料

http://stackoverflow.com/questions/18814566/how-to-add-footer-to-gridview [ ^ ]

https://msdn.microsoft.com /en-us/library/system.web.ui.webcontrols.templatefield.footertemplate(v=vs.110).aspx [ ^ ]

http://www.dotnetfunda.com/articles/show/2741/在网格视图中使用页脚模板 [ ^ ]
See the ref here
http://stackoverflow.com/questions/18814566/how-to-add-footer-to-gridview[^]
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.footertemplate(v=vs.110).aspx[^]
http://www.dotnetfunda.com/articles/show/2741/working-with-footer-template-in-gridview[^]


这篇关于如何在Gridview中添加页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆