【发布时间】:2014-08-27 00:36:10
【问题描述】:
如何在 gridview 中显示可见行的行号?我有这段代码(如下),但它不起作用。
Protected Sub grd_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles grd.DataBound
Dim iNum As Integer = 0
For Each row As GridViewRow In grd.Rows
Dim lblNum As Label = TryCast(row.Cells(0).FindControl("lblNum"), Label)
Dim txtRemark As TextBox = TryCast(row.Cells(10).FindControl("txtRemark"), TextBox)
If row.RowType = DataControlRowType.DataRow Then
If txtRemark.Text = "F" Then
row.Visible = False
ElseIf txtRemark = "P" Then
row.Visible = False
End If
End If
If row.Visible = True Then
iNum += 1
lblNum.Text = iNum
End If
Next
End Sub
【问题讨论】:
-
您遇到错误了吗?
-
no.. 但如果我把它放在 If row.visible 条件中,它不会显示行数。当我删除 If 条件时,它会显示但计数不正确。
-
不确定我是否了解您的需求。你只是想对可见行进行编号吗?你能发布你的 HTML 吗?
-
"lblNum"是 asp 模板的一部分吗? -
@Cory 我添加了我的网格视图的屏幕截图