We help IT Professionals succeed at work.

How do I total columns of a gridview for all pages with paging turned on?

leachj
leachj asked
on
I there a way to total the colums of a gridview for all pages, not just the displayed one?  I can total the column ok, but it will only total the visible page.  I use the datarowbound event of the gridview.  Any suggestions?

Thanks
John

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

        Dim AttendeeTotal As Integer

        If e.Row.RowType = DataControlRowType.DataRow Then
            ' add the Attendees to the running total variables
            AttendeeTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Attendees"))
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(0).Text = "Total of Attendees:"
            ' for the Footer, display the running totals
            e.Row.Cells(1).Text = AttendeeTotal.ToString("d")
            e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
            e.Row.Font.Bold = True
        End If
    End Sub
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
BRONZE EXPERT
Top Expert 2008

Commented:
colums or rows ?

Author

Commented:
columns
IT Pro/Developer
BRONZE EXPERT
Top Expert 2008
Commented:
You have to remove the paging, bind the gridview (GridView1.DataBind()) and count the columns. Then turn on the gridview and bind it. The user will not see this.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.