0

i have the following code:

 <asp:SqlDataSource ID="SqlInvent" runat="server" ConnectionString="<%$ ConnectionStrings:InventConnectionString %>" FilterExpression="(descripcion LIKE '%{0}%') AND model LIKE '%{4}%' AND code_Item LIKE '%{1}%' AND desc_grupo LIKE '%{2}%' AND desc_brand2 LIKE '%{3}%'" 

SelectCommand="SELECT Brand.code_Item, Item_unidad.desc_unidad, Brand.descripcion, Item_grupo.desc_grupo, Item_tipo.Desc_tipo, Item_brand2.desc_brand2, Brand.model FROM Brand INNER JOIN Item_grupo ON Brand.grupo_art_id = Item_grupo.grupo_art_id INNER JOIN Item_brand2 ON Brand.brand2_id = Item_brand2.brand2_id INNER JOIN Item_tipo ON Brand.tipo_art_id = Item_tipo.tipo_art_id INNER JOIN Item_unidad ON Brand.unidad_id = Item_unidad.unidad_id">

<FilterParameters>
                                <asp:ControlParameter ControlID="txtSearch" ConvertEmptyStringToNull="false"  Name="descripcion" PropertyName="Text" />
                                <asp:ControlParameter ControlID="txtSearchCod" ConvertEmptyStringToNull="false" Name="searchcode" PropertyName="Text" />
                                <asp:ControlParameter ControlID="ddlSearchGrupo" ConvertEmptyStringToNull="false" Name="searchGrupo" />
                                <asp:ControlParameter ControlID="ddlSearchBrand2" ConvertEmptyStringToNull="false" Name="searchBrand2" />
                                <asp:ControlParameter ControlID="txtSearchMod" ConvertEmptyStringToNull="false" Name="searchModel" PropertyName="Text" />

                            </FilterParameters>
                        </asp:SqlDataSource>

what does it do.. the SQLDataSource populates a Gridview with 5,000+ items paged on 30 items each, and i have 3 textboxes and 2 dropdownlist so i can search: description, model, code, brand and group

However since im using FilterExpression as follows descripcion LIKE '%{0}%' it would search for the exact word(s) in any place of the string.

ex. if i enter in the textbox red card i would find all the items with red card regarding position

1 red card bla bla

red card blabla

bla bla bla red card

what im trying to do, is to split that word and for me to search individually like ALL items that have red and ALL items that have cards or All the items that contains both words

red cake over the oven

a blue card deck

i have a card that is red

i would like to know if there is any way that i could acomplish this with the current aproach. i have seen other questions, they are similar but doesn't really come close to what am i doing right now.

Javier M
  • 17
  • 8
  • You could split the TextBox content (at spaces) and pass the words to a query similar to the second one in the answer of this post: http://stackoverflow.com/questions/14290857/sql-select-where-field-contains-words. – ConnorsFan Apr 20 '16 at 01:28
  • Try to use Full Text Search feature of SQL server. – Rahul Jain Apr 20 '16 at 10:58
  • @user3151766 i understand how contains and freetext works from SQL and codebehind but right now im working with SQLDataSource and if i use `FilterExpression="(descripcion LIKE '%{0}%') ` it works, but i cannot do something like `FilterExpression="(freetext(descripcion,'{0}'))` bc it throws an error – Javier M Apr 22 '16 at 14:26
  • @ConnorsFan i could, but everything is from coding.. i want to see if there is a way to do it directly as it is right now... – Javier M Apr 22 '16 at 14:27

0 Answers0