DropDownList - pre-position to an entry

L

Larry

If I have a Dropdownlist box with several items in it, and I want to display that listbox to the browser with an entry already selected (which may not necessarily be the last item selected by the user), is there a method that does this?
 
J

Jeffrey Tan[MSFT]

Hi,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, you have a Dropdownlist on your web form, when
user visit your web page, you want to set one of the item in your list to
be selected.
If I misunderstand you, please feel free to point me out.

=============================

Actually, I think you can use DropDownList.SelectedIndex to set the default
selected item's index. Do like this:

private void Button1_Click(object sender, System.EventArgs e)
{
DropDownList1.SelectedIndex=2;
}

Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Simon

Jeffrey,

I'm doing something similar, except I'm using ddl.SelectedValue. On Page_Load this works fine, but if I try the same code elsewhere on the form (ie: a Cancel button to reset the values) then the dropdownlist will always revert to the first element in the list.

Code:
MyDataSet.Merge((DataSet)Session["MyStoredDataSet"]);
MyDataView.RowFilter = "State = " + Session["StoredState"].ToString();
ddlState.DataBind(); // Where SelectedValue is databound to State in MyDataView.


On Page_Load, fine. Elsewhere, uh-uh.

Can you help?

Simon.


----- \"Jeffrey Tan[MSFT]\" wrote: -----


Hi,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, you have a Dropdownlist on your web form, when
user visit your web page, you want to set one of the item in your list to
be selected.
If I misunderstand you, please feel free to point me out.

=============================

Actually, I think you can use DropDownList.SelectedIndex to set the default
selected item's index. Do like this:

private void Button1_Click(object sender, System.EventArgs e)
{
DropDownList1.SelectedIndex=2;
}

Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top