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

4

2 回答 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)

于 2013-10-29T10:23:10.413 回答
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()
于 2013-10-29T10:23:46.890 回答