On Jun 13, 10:07 am, "Aussie Rules" <AussieRu...@nospam.nospamwrote:
Hi,
I have a drop down that I have populated. I am use to using winforms with
the items.add function to add objects to the drop downs, but on web forms it
seems you can only add text string.
How do i then force the drop down to be a specific item in the drop down
(such as setting a default value)
If its possible to add more than just a text string, is it possible to have
an index. For example I want to have a list of countriues in the drop down.
When the user selected a country, say 'France', I am able to access the
index of that item, which may be the 'FR'
Thanks all
Hello!
You can add ListItems to a drop down on webforms
these objects can be created with a display string, and a key string
so if you wanted to add countries, it could be something like:
ddlCountries.Items.Add( new ListItem("Frances", "FR") );
and when wanting to know the value of which item is selected in your
drop down you can just access the SelectedValue property of the
control
string selected = ddlCountries.SelectedValue;
also, in case you wanted to select a specific item via code behind,
you can with the SelectedIndex property
ddlCountries.SelectedIndex =
ddlCountries.Items.IndexOf( ddlCountries.Items.FindByValue( "FR" ) );
hope this is what you were looking for
good luck