Ronda Pederson's Facebook profile

<September 2010>
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789



RSS

Subscribe to the RSS feed for this blog.

Search


(single terms only)

Categories

  • RSS
  • RSS
  • RSS
  • RSS
  • RSS
  • RSS
  • RSS
  • RSS
  • RSS
  • Quote

    Striving to better, oft we mar what's well.
    —Shakespeare

    Blogs I Read

    Links




    Fun

     
       |  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
    posted at 08:43 AM | |