Make a value the default in a databound dropdown

  • Thread starter Thread starter Steve
  • Start date Start date
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.
 
myDropDown.SelectedIndex =
myDropDown.Items.IndexOf(myDropDown.Items.FindByValue("yourDefaultValue"))

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

Karl
 
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
 
Back
Top