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.
Printable View
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.
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
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.
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.
Also This will be helpfull ;)