Hi and thanks in advance
I am trying to implement a search function in which the results can be populated in a gridview. I am using LINQ to query my db in C #.
The problem I'm trying to figure out is that if the user wants to search across multiple columns / fields with multiple search terms, then how can I do this? So, instance, if I look for a table with these three fields, and I had some data like:
firstName | lastname | players
- Michael | Jordan | 12
- Michael | Jordan | 24
- Michael | Jordan | 45
- DeAndre | Jordan | 6
- Jerome | Jordan | 44
- Jordan | Sparks | 88
Now, if I search for Jordan, I get everything:
If I'm looking for Michael Jordan, I should get line number 1,2,3 back.
If I'm looking for Jordan Sparks 88, then I have to translate No. 6 back.
So my problem is that I donβt know where the search term may exist in the table, so I have to search all the columns / fields. In my current code, I have something where I look at each column / field name and use Contains (), then || ("or"), but it only works for 1 search query.
Is there an elegant and easy way to search and filter through the entire linq table so that the list is minimized? From there I will add this result to the data source, and then bind it.
@Sphinxxx I use a typical gridview. It looks like this:
<asp:GridView ID="GridView" runat="server" AllowSorting="True" PagerStyle-Mode="NumericPages" AutoGenerateColumns="false" Width="100%" CssClass="gridView" OnPageIndexChanging="GridView_PageIndexChanging" AllowPaging="True" DataKeyNames="idPlayersList" OnRowCommand="GridView_RowCommand" OnRowEditing="GridView_RowEditing" OnRowCancelingEdit="GridView_CancelEditRow" OnRowUpdating="GridView_UpdateRow" OnRowDataBound="GridView_RowDataBound"> <RowStyle CssClass="rowStyle"></RowStyle> <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" /> <asp:BoundField DataField="PlayersNumber" HeaderText="Players Number" SortExpression="PlayersNumber" /> <asp:TemplateField HeaderText="Team" SortExpression="Team"> <EditItemTemplate> <asp:DropDownList ID="ddlTeam" runat="server" CssClass="dropdown" AutoPostBack="True" AppendDataBoundItems="true" DataTextField="TeamName" DataValueField="idTeam"> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblTeam" runat="server" Text='<%# Bind("TeamName") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>
My current search function looks something like this:
protected void btnSearch_Click(object sender, EventArgs e) {