get values from drop down

J

John

I have a drop down on my form and I need all the values in that drop down
and pass to a stored procedure, how can I get the values of the drop down
and pass them all to my stored procedure call?
 
K

Karl Seguin [MVP]

Do you mean including the none-selected ones?

If it's a server control (ie, asp:dropdownlist) and you enable viewstate
(which it is by default), you can simply loop through it's item collection..

for each item as ListItem in myDropDown.Items
dim value as string = item.Value
..do something
end for

Otherwise, you'll need to use javascrit to highlight every item onSubmit and
use Request.Form
 
T

Tasos Vogiatzoglou

You can't do that from a simple drop-down control because these values
are not posted on the server. If you are talking about a server side
drop-down, then enumerating through Items property for the ListItems of
the control should give you the values.

Regards,
Tasos
 
J

John

its a user control:
<asp:DropDownlList id="ddCars" runat="server"></asp:DropDownList>
when I do a foreach I get an error message
 
J

John

Error:

Error 5 foreach statement cannot operate on variables of type
'ASP.usercontrols_carMakes_ascx' because 'ASP.usercontrols_carMakes_ascx'
does not contain a public definition for 'GetEnumerator'

code on my form that has the user control on it:

void btnGo_Click(object sender, EventArgs e)
{
foreach (ListItem items in CarMake)
{
Response.Write(items.Value);
}
}
and this is a dropdown box not a listbox
 
R

Ray Booysen

John said:
Error:

Error 5 foreach statement cannot operate on variables of type
'ASP.usercontrols_carMakes_ascx' because 'ASP.usercontrols_carMakes_ascx'
does not contain a public definition for 'GetEnumerator'

code on my form that has the user control on it:

void btnGo_Click(object sender, EventArgs e)
{
foreach (ListItem items in CarMake)
{
Response.Write(items.Value);
}
}
and this is a dropdown box not a listbox
Well, no its neither. As the error message shows, CarMake is of type
ASP.usercontrols_carMakes_ascx which is a user control that either you
or your team has developed.

Without further code as to the properties of this usercontrol, we can go
no further.

Kind Regards
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top