tags:

views:

166

answers:

2

If I have a drop down box, how can I have a default selection (know how to do this) which will change to another member in the drop down upon opening of the drop down?

For example: My drop down has 2 values - "Hello", and "Hello Back". "Hello" is the default (0) value, but how can I display "Hello Back" when the drop down box is opened?

Thanks

A: 

u can use Dropdownlist's findbyvalue or findbytext method by giving Hello Back's value or Text as parameter.forexample you can do it so.

dropdownlist1.items.findbytext("Hello Back").selected=true

A: 

You will need to use javascript to implement something like this. A basic example based on what you have requested is:

<script type="text/javascript">
function selectOption()
{
    var thisDLL = document.getElementById("myDDL").options[1].selected = "true";
}
<select id="myDDL" name="myDDL" onclick="javascript:selectOption();">
   <option value="Hello" selected="true" >Hello</option>
   <option value="Hello back" selected="true">Hello back</option>
</select>

Alternatively you could fire the event on using the onFocus event.

EDIT: Fixed error in javascript

Andy Rose