Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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...

share|improve this question
    
What is the question? How do yo create the sql query from the textboxes? –  Jaime Apr 4 '12 at 0: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 Apr 4 '12 at 16:52
add comment

1 Answer

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%'

share|improve this answer
    
Hi Hagbart, I will try it and let you know if that solve my issue. thanks –  ashaked Apr 4 '12 at 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 Apr 4 '12 at 20:30
    
The other option is adding more search filters option for each column (meaning the SQL query will look like "WHERE column_name like '%xxx%' or column_name like '%yyy'%' or column_name like '%zzz%' etc.) Can you please advice the right approach? Thanks again –  ashaked Apr 4 '12 at 20:31
    
Any ideas? Still stuck on this one... –  ashaked Apr 5 '12 at 20:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.