如何在RadGrid Telerik中显示页脚的总列数

时间:2012-01-03 12:05:58

标签: asp.net telerik-grid radgrid

如何在Telerik中显示RadGrid页脚的总列数?

2 个答案:

答案 0 :(得分:5)

您需要绑定到ItemDataBound事件:

int counter = 0;

void Grid_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) {
      if(e.Item is GridDataItem) {
         GridDataItem dataItem = e.Item as GridDataItem;
         counter += Convert.ToInt32(dataItem["SomeField"].Text);
      }
      else if(e.Item is GridFooterItem) {
         GridFooterItem footerItem = e.Item as GridFooterItem;
         FooterItem["YourFooterColumn"].Text = counter.ToString();
      }
 }

答案 1 :(得分:2)

Erik提供的解决方案也在发挥作用。 但Radgrid为此提供了内置专栏。

<telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double"
                    DataFields="UnitPrice, UnitsInStock" Expression="{0}*{1}" FooterText="Total : "
                    Aggregate="Sum" />

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx