shirish
shirish

Reputation: 67

How to show total of columns at footer in RadGrid Telerik

How to show total of columns at RadGrid footer in Telerik?

Upvotes: 1

Views: 19494

Answers (2)

Jayesh Goyani
Jayesh Goyani

Reputation: 11154

The solution which was given by Erik is also working. But Radgrid have inbuilt column for this.

<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

Upvotes: 3

Erik Dekker
Erik Dekker

Reputation: 2433

You need to bind to the ItemDataBound event:

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();
      }
 }

Upvotes: 5

Related Questions