如何使用asp.net在gridview的单元格中查找值 [英] How to find a value in cells of gridview using asp.net
问题描述
这里我的代码:
Private Sub CountTpHo()
尝试
Dim NHNo As Integer = 0
Dim XKLD As Integer = 0
Dim TNXH As Integer = 0
For i As Integer = 0 to dgInput.Rows.Count - 2
如果dgInput.Rows(i).Cells(Tp)。值类似abc,那么
NHNo = NHNo + 1
结束如果
下一页
lblNNNT1.Text = NHNo.ToString
Catch ex As Exception
MessageBox.Show(ex.ToString)
结束尝试
结束子
当我浏览时,得到一个错误:
错误:
'Value'不是'System.Web.UI.WebControls.TableCell'的成员。
我试图谷歌,并将 dgInput.Rows(i).Cells(Tp)。值 更新为 dgInput.Rows(i).Cells(Tp)。Text - >不工作,得到错误:
System.InvalidCastException:从字符串Tp到Integer类型的转换无效。
期待您的回复。最好的感谢
Here my code:
Private Sub CountTpHo()
Try
Dim NHNo As Integer = 0
Dim XKLD As Integer = 0
Dim TNXH As Integer = 0
For i As Integer = 0 To dgInput.Rows.Count - 2
If dgInput.Rows(i).Cells("Tp").Value Like "abc," Then
NHNo = NHNo + 1
End If
Next
lblNNNT1.Text = NHNo.ToString
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
When I browse, get an ERROR:
ERROR:
'Value' is not a member of 'System.Web.UI.WebControls.TableCell'.
I tried to google, and update dgInput.Rows(i).Cells("Tp").Value into dgInput.Rows(i).Cells("Tp").Text --> Not work, get error:
System.InvalidCastException: Conversion from string "Tp" to type 'Integer' is not valid.
Looking forward your replies. Best thank
推荐答案
除了将Value更改为Text之外,cells()还需要一个整数索引。因此,将其更改为Tp列的索引号。
Besides the changing of Value to Text, the cells() expects an integer index. So change it to index number of the "Tp" column.
这篇关于如何使用asp.net在gridview的单元格中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!