Blog Stats
  • Posts - 4
  • Articles - 0
  • Comments - 6
  • Trackbacks - 4

 

Adding totals to telerik grid

First, you'll need to define a global variable to hold the value to be displayed in the footer.

Public ClmTotChg As Integer = 0
Public ClmTotBal As Integer = 0

Then, you'll need to populate the variable.  This is where it gets tricky.  In order for this to work, you must set the “DataMember“ property of the MasterTableView or DetailTableView for the footer you want a total in.  You'll also need to set the ShowFooter value to true.  For instance...

<MasterTableView DataMember="CLAIM" DataKeyNames="CLMNO" ShowFooter="True">

Next, you will need to populate the variable when a detail item is added to the grid.  You will do this in the “ItemDataBound“ event on the grid.

'The following is used to update the total fields for the footer on the Claim Header grid
If
TypeOf e.Item Is GridDataItem And e.Item.OwnerTableView.DataMember = "CLAIM" Then
   Dim gridItem As GridDataItem = CType
(e.Item, GridDataItem)
   Select Case
gridItem.ItemType
      Case
GridItemType.AlternatingItem, GridItemType.Item
         ClmTotChg += gridItem("CLMAMT"
).Text
         ClmTotBal += gridItem("CLMBAL").Text
   End
Select
End If

Finally, you'll need to add the totals to the footer.

'The following is used to add a footer to the Claim Header grid that will show the totals
If TypeOf e.Item Is GridFooterItem And e.Item.OwnerTableView.DataMember = "CLAIM"
Then
   Dim footerItem As GridFooterItem = CType
(e.Item, GridFooterItem)
   footerItem("CLMAMT").Text = Format$(ClmTotChg, "$#,###,##0.00"
)
   footerItem("CLMBAL").Text = Format$(ClmTotBal, "$#,###,##0.00"
)
End If

That's all there is to it.

 


Feedback

# re: Adding totals to telerik grid

Gravatar With regard to:
Finally, you'll need to add the totals to the footer.

What event? 10/6/2007 12:11 PM | Tom

# re: Adding totals to telerik grid

Gravatar The code to add the total to the footer is part of the ItemDataBound code. It should be near the end of the event code since the footer is likely to be created last. 10/8/2007 10:23 AM | MAPSR80

Post a comment





 

Please add 7 and 8 and type the answer here:

 

 

Copyright © Mark Pritchard