Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering Dataview

Status
Not open for further replies.

WelshyWizard

IS-IT--Management
Apr 23, 2006
89
GB
Hi all,

I've got the following code that helps the user filter a dataview on a series of textboxes.

Code:
DataView1.RowFilter = "(Title Like '*" & TextBox3.Text & "*' OR Description Like '*" & TextBox3.Text & "*') AND UserRep Like '" & TextBox1.Text & "'"

What I want is for the user to be able to add a string of words in TextBox3. For example.

If a record had the Title: "Ways to wash dirty underwear" and the user entered "ways underwear" (or something like that), the record would be filtered out... Similar to Google really. At present the user can only enter one word.

Cheers.

Today is the tomorrow you worried about yesterday - and all is well.....
 
That is not easy as ADO.NET does not support FreeText searching.

What you need to do is split the text and make each word a seperate LIKE.

Code:
Dim words As String() = TextBox3.Text.Split(" ")
        Dim filter As String = ""
        Dim first As Boolean = True
        For Each word As String In words
            If first Then
                filter = "Description LIKE '*"
                first = False
            Else
                filter += " AND Description LIKE '*"
            End If
            filter += word + "*' "
        Next

        DataView1.RowFilter = "(Title Like '*" & TextBox3.Text & "*' OR " & filter & ") AND UserRep Like '" & TextBox1.Text & "'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top