Ronda's Web Log - comments


Entry
 |  Total Summary Rows in Datagrid with DataItem
There are a gazillion ways to create a summary row in the footer of a datagrid. I think this is one of the slicker, faster ways. Using the dataitem enables you to use friendly names and variables throughout - so when you have many many columns it makes it a lot easier to keep track and manage.

Declare some integers for holding the values



Private MonthlyGoal As Integer = 0
Private FiscalYrYTD As Integer = 0

In your Databound event add up the values:

Public Sub dgAttainment_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

‘add the items as you bind each row
‘Intellisense will not have the datafield name when you choose
‘e.item.dataitem but just add it anyways – it is the datafield
‘that you have used in your datagrid column

MonthlyGoal += e.Item.DataItem.MonthlyGoal
FiscalYrYTD += e.Item.DataItem.FiscalYrYTD

ElseIf (e.Item.ItemType = ListItemType.Footer) Then

‘put the added values into the appropriate column in the footer

e.Item.Cells(6).Text = FormatCurrency(MonthlyGoal, 2)
e.Item.Cells(9).Text = FormatCurrency(FiscalYrYTD, 2)

end if

End Sub

Comments


Add your own comment

(To send a private comment, use the email page.)

Name:  
Email:
Homepage:
Validation What is the sum of: 104 and 109
  Comment (No HTML) :



Count:
 
of 1800 

  Close comment window