简体   繁体   English

VB.Net搜索复选框列表

[英]VB.Net Search Check Box List

I have a checkbox list containing the entries from my database. 我有一个复选框列表,其中包含数据库中的条目。 I also have a search bar at the top of the page. 页面顶部也有一个搜索栏。 How can I search for a checkbox using the search bar. 如何使用搜索栏搜索复选框。 What I am doing now is not returning anything to screen, it just remains at the same screen. 我现在正在做的是不返回任何屏幕内容,而是保留在同一屏幕上。 My checkbox list id is check1 and my search bar id is search. 我的复选框列表ID为check1,搜索栏ID为search。 So on click of my search button I run the following code: 因此,单击我的搜索按钮后,我运行以下代码:

check1.Items.FindByText(searchText.Text)

ASP: ASP:

<asp:TextBox ID="searchText" placeholder="Search For Customer:" AutoPostBack="true" TextAlign="Right" runat="server" Width="448px"></asp:TextBox>
<asp:Button ID="search" runat="server" text="Search" />

What's wrong here? 怎么了 Thanks 谢谢

FindByText returns a ListViewItem. FindByText返回一个ListViewItem。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listitemcollection.findbytext.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.listitemcollection.findbytext.aspx

When you say "it just remains at the same screen", do you mean your listview doesn't update and you expected it to? 当您说“它只是停留在同一屏幕上”时,您是说您的列表视图没有更新,您希望它会更新吗? You'll have to handle that on your own. 您必须自己处理。

Since your lv is bound, you can either filter your bound dataset and rebind it (LINQ is good here) or you can call a stored procedure that will return results based on that search text. 由于lv已绑定,因此您可以过滤绑定的数据集并重新绑定(LINQ在这里很好),也可以调用存储过程,该存储过程将基于该搜索文本返回结果。 You'll want to use something along the lines of: 您将需要使用以下方法:

SELECT  Field1, Field2, FieldN
FROM    Table
WHERE   FieldToSearch LIKE '%' + @searchText + '%'

Again, read the documentation on methods, controls, etc. that you're unfamiliar with. 同样,请阅读您不熟悉的有关方法,控件等的文档。 If you did so, you'd see that you only get the item back, not filtering the listview. 如果这样做,您会看到您只取回该项目,而不过滤列表视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM