在文本框空白处,我想清除我的 gridview 源
但是我无法在 vb.net 中做到这一点。
在引用了几个答案后,我尝试了以下不成功的尝试:
grdUsers.rows.clear()
:不适用于 vb.net
grdUsers.DataSource=""
grdUsers.columns.clear()
但是没有成功。
请帮我清除gridview的数据源。
最佳答案
如果您的 DataGridView 绑定(bind)到 DataSource 并且您想要清除它,那么您可以使用 Nothing
关键字,后跟 DataBind()
。
grdUsers.DataSource = Nothing
grdUsers.DataBind()
这里是more information on the DataBind() method .
<小时/>如果您想在 TextBox1 中的文本为空时清除行,您可以为文本框创建一个 TextChanged 事件...
Private Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim = "" Then
grdUsers.DataSource = Nothing
grdUsers.DataBind()
End If
End Sub
关于asp.net - 在vb.net中根据特定条件清除gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19050906/