Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2745
Set Initial Value of WebDropDown
posted

Ciao!

I have a page with three dropdown boxes, we can call them dropdown1, dropdown2 and dropdown3. When the value in dropdown1 is changed, the value in dropdown2 should change and son on with dropdown3. Using the valuechanged server event this works fine, when changes are made on the client side.

Now i want to set the initial value of dropdown1 (selected value) and I cant get that to work. The first dropdown contains available languages and I want to set this according to the language used in the current browser. I have the language to use, but i don't know how and where to set this initial value.

i tried to set the value in the dropdown1's DataBound event but when I do that it doesn't fire any other event in the hierarchy, like dropdown1_ValueChanged.  i suppose that that event only fires when something is happening on the client side...

what is the best solution for setting the initial value in my case?

thanks for helping out!

/Henrik

Parents
  • 24671
    Suggested Answer
    posted

    Hi Henrik,

    If you want to only change the text in the input, you can set the CurrentValue property. This won't make anything selected though. If you want to mark initially selected item - you have two choices:

    1) just set the SelectedItemIndex to the index of the item in the collection (this will also update the current value)

    2) set the SelectedValue to the item's "Value" property - this will also update the current input value with the item's Text. (you can map the Value property of the item to some unique ID field in the database). 

    Hope it helps. Please let me know if i can help with anything else,

    Angel 

Reply Children