473,383 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Search with drop down list

Hello!

I have 4 diffrent drop downlist. I want a user to select a value from a
drop down list, and place it in a SELECT statement. How would I put that
value in the select statement. And if the user selects two items, one item
from two diffrent drop down list, how would I do that? Any suggestions would
be great!

TIA!!

Rudy
Nov 19 '05 #1
4 2103
Look up "sql injection attacks" and take necessary precautions in your code
to protect.

in C#
---------
string sPetType;
sPetType = ddPetTypes.SelectedValue;

string sSQL = " SELECT * FROM tblPets WHERE pettype = '" + sPetType + "'";
and in VB .NET
-------------
dim sPetType as string
sPetType = ddPetTypes.SelectedValue

dim sSQL as string = " SELECT * FROM tblPets WHERE pettype = '" & sPetType &
"'"

Note the single qotes since in this case I am assuming that sPetType is a
string and would need the single quotes in the SQL

"Rudy" <Ru**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hello!

I have 4 diffrent drop downlist. I want a user to select a value from a
drop down list, and place it in a SELECT statement. How would I put that
value in the select statement. And if the user selects two items, one item
from two diffrent drop down list, how would I do that? Any suggestions
would
be great!

TIA!!

Rudy

Nov 19 '05 #2
Hi Tarren!
Thank you for the info, worked out great! I'm working in VB.net, appreciate
both versions. I plan to use all store procedures in my code before I go
live. For now, it's easier doing it this way instead of always changeing the
SP around.

I do have one more quick question, If I run ths select statement, how can
have the results show up on another page. For now, I have the seach fields
on the same page as the results, but I want to move my search panel to a
diffrent page.

Thank you for your help!!!

Rudy

"Tarren" wrote:
Look up "sql injection attacks" and take necessary precautions in your code
to protect.

in C#
---------
string sPetType;
sPetType = ddPetTypes.SelectedValue;

string sSQL = " SELECT * FROM tblPets WHERE pettype = '" + sPetType + "'";
and in VB .NET
-------------
dim sPetType as string
sPetType = ddPetTypes.SelectedValue

dim sSQL as string = " SELECT * FROM tblPets WHERE pettype = '" & sPetType &
"'"

Note the single qotes since in this case I am assuming that sPetType is a
string and would need the single quotes in the SQL

"Rudy" <Ru**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hello!

I have 4 diffrent drop downlist. I want a user to select a value from a
drop down list, and place it in a SELECT statement. How would I put that
value in the select statement. And if the user selects two items, one item
from two diffrent drop down list, how would I do that? Any suggestions
would
be great!

TIA!!

Rudy


Nov 19 '05 #3
Use a sql trick something like this in a stroed procedure

@selectedNumber as int
@selectedText as nvarchar(20)

select * from table_name
where (@selectedNumber=-1 OR numericColumn=@selectedNumber)
and (@selectedText='' or textColumn=@selectedText)
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Rudy" <Ru**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hello!

I have 4 diffrent drop downlist. I want a user to select a value from a
drop down list, and place it in a SELECT statement. How would I put that
value in the select statement. And if the user selects two items, one item
from two diffrent drop down list, how would I do that? Any suggestions
would
be great!

TIA!!

Rudy

Nov 19 '05 #4
Rudy:

What I have done is have the drop downs fire a response.redirect. So it
would look something like this

VB .NET

PAGE WITH SEARCH PANEL
dim sQueryString as string
sQueryString = "?pettype=" & Server.URLEncode(ddPetTypes.SelectedValue)

Response.Redirect("otherpage.aspx" & sQueryString)

THEN IN THE OTHER PAGE YOU CAN PUT IN PAGE_LOAD METHOD

if Request.QueryString("pettype").Length > 0 then 'check to make sure this
page was called with the querystring
dim sSQL as string = " SELECT * FROM tblPets WHERE pettype = '" &
Server.URLDecode(Request.QueryString("pettype") & "'"
end if
You need the URLEncode and URLDecode so you can pass spaces and non
alphanumeric characters through the querystring and then turn them back into
usable values for a string match in the SQL

Also, make sure the querystring element is present, which is why I put the
if block. In VB .NET you can check for length, and it'll come back as zero
if the element isn't there.

In C# you have to check for != null since you cannot check the length of an
element that does not exist and C# is more strict on that point. :)

For some of the apps I write, I make the Search bar a usercontrol and then
handle the response.redirect from within the user control so I only write
the querystring prep once and have it Response.Redirect, from anywhere in my
site.

Hope this helps!
"Rudy" <Ru**@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
Hi Tarren!
Thank you for the info, worked out great! I'm working in VB.net,
appreciate
both versions. I plan to use all store procedures in my code before I go
live. For now, it's easier doing it this way instead of always changeing
the
SP around.

I do have one more quick question, If I run ths select statement, how can
have the results show up on another page. For now, I have the seach
fields
on the same page as the results, but I want to move my search panel to a
diffrent page.

Thank you for your help!!!

Rudy

"Tarren" wrote:
Look up "sql injection attacks" and take necessary precautions in your
code
to protect.

in C#
---------
string sPetType;
sPetType = ddPetTypes.SelectedValue;

string sSQL = " SELECT * FROM tblPets WHERE pettype = '" + sPetType +
"'";
and in VB .NET
-------------
dim sPetType as string
sPetType = ddPetTypes.SelectedValue

dim sSQL as string = " SELECT * FROM tblPets WHERE pettype = '" &
sPetType &
"'"

Note the single qotes since in this case I am assuming that sPetType is a
string and would need the single quotes in the SQL

"Rudy" <Ru**@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
> Hello!
>
> I have 4 diffrent drop downlist. I want a user to select a value from
> a
> drop down list, and place it in a SELECT statement. How would I put
> that
> value in the select statement. And if the user selects two items, one
> item
> from two diffrent drop down list, how would I do that? Any suggestions
> would
> be great!
>
> TIA!!
>
> Rudy


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
0
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
2
by: leeperman | last post by:
In Dreaweaver I cannot filter my database results to display only specific data that is retrieved from mulptile drop down list on my search page. The drop down list selections are posted to my...
0
by: StarLavender | last post by:
Hi. I want to create a search form using the drop down list and checkbox. First, the users have to select from drop down list whether they want to search by date or id. After that, for example, a new...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.