Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter list in asp.net/vb.net using linq

Tags:

asp.net

linq

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

like image 638
Mayur Avatar asked Oct 28 '25 08:10

Mayur


1 Answers

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)

like image 119
Tim Schmelter Avatar answered Oct 30 '25 23:10

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!