Dynamically create new field search group with multiple filter fields

Go To StackoverFlow.com

2

I searched but I could not find anything similar to what I need so I will appreciate your help. I have an aspx page that I want to create new textbox fields dynamically upon user request (this is the easy part). The user can ask for any number of fields since they will be used to filter an SQL server table. To make a long story short the table has 23 columns and the user can create multiple textbox for each column so that the general SQL query will search according to the text he will enter in those textbox. For instance - the user can choose the 'type' field and create 3 textbox which he will enter 'b' for the first, 'c' for the second and 'e' for the third so the query will look something like that:

SELECT *
FROM table_name
WHERE type like '%b%' or type like '%c%' or type like '%e%'

I hope you can understand what I'm looking for, Any help will be great...

2012-04-03 23:37
by ashaked
What is the question? How do yo create the sql query from the textboxes - Jaime 2012-04-04 00:09
Hi Justin, The question is how do I create the SQL query from the text boxes but I need to add another issue. I can be dealing with different number of filters (= text boxes) for every header. Here is an example to explain: The user choose 3 filters for type column ('a', 'b', 'e') 2 filters for the name column ('shak', 'justin') and 1 more for the paused column ('yes')

So I got myself different number of text boxes which I need to create and than use for my SQL query - ashaked 2012-04-04 16:52



0

Do a for each loop with all the relevant textboxes. In there you can create the SQL Query and add or type like '%X%' blocks for any nuber of textboxes the user has created. This way the SQL Query will always have the dynamic count of or type like '%c%'

2012-04-04 12:03
by Hagbart Celine
Hi Hagbart, I will try it and let you know if that solve my issue. thank - ashaked 2012-04-04 16:57
Hi again @Jaime, I understood Hagbart answer but now I'm facing problems creating those text boxes in run time. The user has two options he can press. One will create more filter options according to the columns names (meaning the SQL query will look for "WHERE column_name like '%xxx%') - each column will have his own line and the choosing of the column name is done using a dropdownlist with the possible column names - ashaked 2012-04-04 20:30
The other option is adding more search filters option for each column (meaning the SQL query will look like "WHERE columnname like '%xxx%' or columnname like '%yyy'%' or column_name like '%zzz%' etc.) Can you please advice the right approach? Thanks agai - ashaked 2012-04-04 20:31
Any ideas? Still stuck on this one.. - ashaked 2012-04-05 20:04