Monday, March 26, 2012

Maintain Default Value In DropDownList Box

My ddl is populated via a DB. When the user makes a selection the value sends them to a results page which triggers a query with appropriate results-no problem. Now when the user returns to the previous page, i.e. the search page with the dropdownlist box the default value does not appear, the value that was previous selected remains selected.

I need the ddl to go back to Index= 0. I have tried various flavors of ddlMyddl.SelectedIndex.Value = 0 without success.

How should it be coded and where do I place the code?

T.Y.

MsLadyGeeYou could try

ddlMyddl.SelectedIndex = 0;
if the index of the default item is 0. or
ddlMyddl.SelectedValue = "VALUE";
where "VALUE" is the value of the default item.

hope this helps,
sivilian
This should be what you're after:

ddlMyDropDownList.ClearSelection()

AJN
The following did not work.
1) ddlMyddl.SelectedIndex = 0;
2) ddlMyddl.SelectedValue = "VALUE";

What has finally worked for me was to place a link back to the previous page and now the ddllistbox reflects the default index of "0".

Now I need to disable the back button.
ddlMyDropDownList.ClearSelection()--did not work for me.

What has finally worked for me was to place a link back to the previous page and now the ddllistbox reflects the default index of "0".

Now I need to disable the back button.

T.Y.

MsLadyGee
That's the browser trying to be smart (and you probably appreciate that after filling a long form, you can click back and find everything you typed still there).
So to get the initial state of the page instead, you'll need to write a little bit of javascript.
For example:
<body onload="myDropDownListID.selectedIndex=0">

0 comments:

Post a Comment