使用复选框过滤Gridview行.需要一些人来检查代码. [英] Filter Gridview Rows With Checkbox. Need Some One To Check Codes.

查看:95
本文介绍了使用复选框过滤Gridview行.需要一些人来检查代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想使用以下控件来过滤Gridview1,将其控制复选框和代码过滤为:如果FirstName列的GridView1行的值为"John",则仅显示此行.
我可以通过网络以某种方式编写此代码.但是代码无法正常工作,而且我也不知道如何为其他行添加控件,例如"James","Paul" ...

Hello,

I would like to filter Gridview1 with, control checkbox, and code as: If GridView1 rows of column FirstName have value ''John'' then show only this rows.

I have somehow with network help write this code. But code is not working as it should, and also I do not know how to add controls also for other rows with values such as ''James'', ''Paul''...

For Each x As GridViewRow In Me.GridView1.Rows
If Not x.Cells(0).Value = "John" Then
x.Visible = False
End If
Next





Database:<br />
FirstName; SecondName<br />
James ; White<br />
John ; Brown<br />
Paul ; Red<br />
John ; Black<br />
Paul ; Blue<br />
James ; Green


因此,需要帮助的人,给小费或显示如何变得更容易.

预先感谢您的帮助.


So, need someone for help, to give a tip, or to show how would be easier.

Thank you in advance for help.

推荐答案

您可以使用DataView及其行过滤器属性.

在filter事件中,只需使用dataview过滤数据,然后将过滤后的dataview用作网格的源即可.

若要了解更多信息,请阅读此处: http://msdn.microsoft.com /en-us/library/system.data.dataview.rowfilter.aspx [
You can use DataView and it''s row filter property.

On the filter event, just filter the data using a dataview and then use the filtered dataview as the source of your grid.

To know more of it, read here: http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx[^]


如果有人需要,这是我的最新代码:

Here is my latest code if someone maybe need it:

<pre lang="vb">Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
       SqlDataSource1.SelectCommand = "SELECT * FROM MAIN WHERE FIRSTNAME like ''%" & TextBox1.Text & "%'' and secondname like ''%" & TextBox2.Text & "%''"<br />
<br />
       SqlDataSource1.DataBind()<br />
<br />
   End Sub</pre><br />


这篇关于使用复选框过滤Gridview行.需要一些人来检查代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆