如何在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
答案 0 :(得分:0)
试试这个
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 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.Text = "P" Then
row.Visible = False
Else
iNum += 1
TryCast(row.Cells(0).FindControl("lblNum"), Label).Text = iNum
End If
End If
Next
End Sub