在 vb.net 中在特定条件下清除 gridview

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19050906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:15:42  来源:igfitidea点击:

Clearing gridview upon certain condition in vb.net

asp.net.netvb.netgridview

提问by C Sharper

on textbox blank, i wanted to clear my gridview source

在文本框空白上,我想清除我的 gridview 源

But i was not able to do it in vb.net.

但我无法在 vb.net 中做到这一点。

After referring several answers i tried following unsuccessfull attempts:

在参考了几个答案后,我尝试了以下不成功的尝试:

grdUsers.rows.clear(): Does not work with vb.net

grdUsers.rows.clear(): 不适用于 vb.net

grdUsers.DataSource=""

grdUsers.columns.clear()

But it does not worked out.

但它没有解决。

Please help me to clear my datasource of gridview.

请帮我清除我的 gridview 数据源。

回答by Alex

If your DataGridView is bound to a DataSource and you want to clear it then you can use the Nothingkeyword followed by a DataBind().

如果您的 DataGridView 绑定到一个 DataSource 并且您想清除它,那么您可以使用Nothing关键字后跟一个DataBind().

grdUsers.DataSource = Nothing
grdUsers.DataBind()

Here is more information on the DataBind() method.

以下是有关 DataBind() 方法的更多信息



If you want to clear your rows when the text is empty in TextBox1, you would create a TextChanged event for your textbox ...

如果要在 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