get values from drop down

  • Thread starter Thread starter John
  • Start date Start date
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?
 
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
 
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
 
its a user control:
<asp:DropDownlList id="ddCars" runat="server"></asp:DropDownList>
when I do a foreach I get an error message
 
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
 
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
 
Back
Top