如何在gridview中查找记录/行的总数?

时间:2012-09-14 17:24:28

标签: .net vb.net gridview gridviewrow

我想在gridview中找到总行数。这是我的代码,页面大小= 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

页脚在第一页显示为10 0 50,但我想显示为50的1-10。在第二页中它显示相同,但​​我想显示为50的11-20.任何人都可以告诉我如何显示这样的页脚文本。

1 个答案:

答案 0 :(得分:4)

是的,您必须声明一个变量来赋值该函数的值。

Dim int as integer

int = CustomGridView1.Rows.Count()

.Count()函数返回一个整数值。您必须将该整数值存储在某处,否则调用该函数没有意义。

编辑-----

也许是这样的

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           

这是我最好的猜测。我通常不使用页脚。