4

I have a list of class

How can I filter on some condition..I am applying following it is working when value gets exact match

        Dim result = obj.OfType(Of clsEmrItmMstr)().Where(Function(s) s.GenName Like         txtserach.Text)
        grddetails.DataSource = result
        grddetails.DataBind()

where "clsEmrItmMstr" is my class name and "GenName" is field in class

2 Answers 2

5

Instead of the Like operator you could simply use String.Contains:

Dim result = obj.OfType(Of clsEmrItmMstr)().
    Where(Function(s) s.GenName.Contains(txtserach.Text))

With Like you need * as wildcard, so this should work:

Dim result = obj.OfType(Of clsEmrItmMstr)().
    Where(Function(s) s.GenName Like String.Format("*{0}*", txtserach.Text))

(assuming that you want to find all objects where the GenName contains the text entered in the TextBox)

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Contains function

Dim result As dynamic = obj.OfType(Of clsEmrItmMstr)().Where(Function(s) s.GenName.Contains(txtserach.Text))
grddetails.DataSource = result
grddetails.DataBind()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.