Results 1 to 6 of 6

Thread: [2005] Add Rows to Bound Gridview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    [2005] Add Rows to Bound Gridview

    how would I add rows to the footer of a gridveiw. Trying to add some subtotals/totals to a gridview that's already been bound.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: [2005] Add Rows to Bound Gridview

    If AutoGenerateColumns is True you could use the RowDatabound event to capture the totals and then simply display them in the proper cell of the Footer row. Something like

    Code:
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Private sngAmount As Single
    
        Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    
            Select Case e.Row.RowType
                Case DataControlRowType.DataRow
                    sngAmount = sngAmount + CSng(e.Row.Cells(2).Text)
                Case DataControlRowType.Footer
                    e.Row.Cells(2).Text = sngAmount.ToString
            End Select
    
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] Add Rows to Bound Gridview

    Thanks for the suggestion Bruce, but I was looking to add more than one. It's really not a big deal though as I just added a html table below the grid with the fields that I want to display. Was just thinking there would be a better way.

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2005] Add Rows to Bound Gridview

    what about using Template column so you can display add Lable control in that and during RowDataBound event,if DataControlRowType.Footer than find that label control and use underlying Datatable's Compute method to get Sub/Total of particular column.
    __________________
    Rate the posts that helped you

  5. #5
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2005] Add Rows to Bound Gridview

    Also This will be helpfull
    __________________
    Rate the posts that helped you

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add Rows to Bound Gridview


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width