ewein
ewein

Reputation: 2735

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. So on click of my search button I run the following code:

check1.Items.FindByText(searchText.Text)

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

Upvotes: 0

Views: 1134

Answers (1)

Yatrix
Yatrix

Reputation: 13775

FindByText returns a ListViewItem.

http://msdn.microsoft.com/en-us/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. 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.

Upvotes: 1

Related Questions