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.