How to find total number of records/rows in gridview?

software picture software · Sep 14, 2012 · Viewed 20.9k times · Source

I want to find total number of rows in the gridview. here is my code, page size= 10

   Private Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles CustomGridView1.RowDataBound
    Dim Count As Integer = CustomGridView1.Rows.Count()
    If e.Row.RowType = DataControlRowType.Footer Then
        e.Row.Cells(5).Text = Count & " of " & getstudents.Count()
    End If
End Sub

Footer shows as, 10 0f 50 in the first page but I want to show as 1-10 of 50 . In the second page it shows the same but I want to show as 11-20 of 50. Can anyone tell me how to show footer text like this.

Answer

Ccorock picture Ccorock · Sep 14, 2012

Yeah you have to declare a variable to assign the value of that function to.

Dim int as integer

int = CustomGridView1.Rows.Count()

The .Count() function returns an integer value. You must store that integer value somewhere, otherwise there is no point in calling the function.

Edit-----

Maybe something like this

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.Footer Then
            e.Row.Cells(2).Text = (variable you defined above)
        End If
    End Sub           

Just my best guess on this one. I don't usually use the footers.