Make a value the default in a databound dropdown

S

Steve

I have a databound dropdown in my page. I want to make one of the
values the default value. Any ideas?

Just to explain further, I have also appended one item to the dropdown,
using the AppendDataBoundItems="True" property of the dropdown.
Unfortunately the item I have appended to the dropdown has become the
default value of the dropdown list which is not what I want.

Kind regards,

Steve.
 
K

Karl Seguin [MVP]

myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByValue("yourDefaultValue"))

you can also use FindByText which uses the text, instead of the value.

Karl
 
S

Steve

Thank you for this Karl.

Should I put this code in the page load event in page behind or can I
somehow put it as a parameter in between the dropdown tags in the page
itself.

Kind regads,

Steve
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top