954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to make the search function with dropdownlist on asp.net

Hi guys,
i am creating a search function on my web. This is the result

"SELECT [ROUTE], [INST_KEY], [INST_TYPE], [ACCT_KEY], [STATUS], 
                        [DMZ], [CUST_NAME], [ADDRESS_LINE1], [ADDRESS_LINE3], [ADDRESS_LINE4], [ADDRESS_LINE5], 
                        [METER_KEY], [SIZE], [INSTALL_DATE], [X], [Y], [Z], [ADDRESS_LINE2], [MI_PRINX] FROM [DBCUSTOMER] 
                        WHERE ([CUST_NAME] LIKE '%' + @CUST_NAME + '%')"


This function just looking one field. I try for modify it to can the user choose category on dropdownlist, his will can get data which his choice.

How can i do build the search function like that?
The following picture is what I mean.

Thanks,
Regards, Kiki Wisaka

Attachments search_with_option.jpg 34KB
kikiwisaka
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

If you intend to have the dropdown box have the various categories such as name, address, date and then a textbox that takes the actual search time all you need to do is include the selected item from the dropdown into the sql query along with the search term.
E.g. imagine I selected name in the list and entered a name as the search term in the textbox.

"SELECT [ROUTE], [INST_KEY], [INST_TYPE], [ACCT_KEY], [STATUS],
    [DMZ], [CUST_NAME], [ADDRESS_LINE1], [ADDRESS_LINE3], [ADDRESS_LINE4], [ADDRESS_LINE5],
    [METER_KEY], [SIZE], [INSTALL_DATE], [X], [Y], [Z], [ADDRESS_LINE2], [MI_PRINX] FROM [DBCUSTOMER]
    WHERE (" + dropDownList.selectedItem.ToString() + " LIKE '%' + @CUST_NAME + '%')"

Obviously the list can be added as a parameter as cust_name is.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 168
 

If you intend to have the dropdown box have the various categories such as name, address, date and then a textbox that takes the actual search time all you need to do is include the selected item from the dropdown into the sql query along with the search term. E.g. imagine I selected name in the list and entered a name as the search term in the textbox.

"SELECT [ROUTE], [INST_KEY], [INST_TYPE], [ACCT_KEY], [STATUS],
    [DMZ], [CUST_NAME], [ADDRESS_LINE1], [ADDRESS_LINE3], [ADDRESS_LINE4], [ADDRESS_LINE5],
    [METER_KEY], [SIZE], [INSTALL_DATE], [X], [Y], [Z], [ADDRESS_LINE2], [MI_PRINX] FROM [DBCUSTOMER]
    WHERE (" + dropDownList.selectedItem.ToString() + " LIKE '%' + @CUST_NAME + '%')"

Obviously the list can be added as a parameter as cust_name is.

Thank you for your answer. But after i try with your code and then the result isIncorrect syntax near the keyword 'LIKE'
so. How to solve this problem?:)... And what the mean Obviously the list can be added as a parameter as cust_name is?:)

kikiwisaka
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Well you could have this for the last part of the SQL:
WHERE (@listItem LIKE '%' + @CUST_NAME + '%')"

and use parameters for the @listItem as you have for @CUST_NAME.

As for the error, your SQL string will have a mistake in it. Looking at what I typed it maybe the quotes marks around the % are the problem. Try
WHERE " + dropDownList.selectedItem.ToString() + " LIKE %' + @CUST_NAME + '%"

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 168
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: