Created
October 5, 2009 02:51
-
-
Save jpoehls/201827 to your computer and use it in GitHub Desktop.
ASP.NET DropDownList SelectedValue & ViewState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected string MySelectedValue | |
{ | |
get | |
{ | |
return (ViewState["MySelectedValue"] == null) | |
? null : ViewState["MySelectedValue"].ToString(); | |
} | |
set | |
{ | |
ViewState["MySelectedValue"] = value; | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
// Check if the selectedValue has changed. | |
string selectedValue = Request[myDropDownCtrl.UniqueID]; | |
if (selectedValue != MySelectedValue) | |
{ | |
// Value has changed, do whatever you | |
// would do in the SelectedIndexChanged event here. | |
} | |
MySelectedValue = selectedValue; | |
// TODO: Populate the drop-down control | |
PopulateMyDropDownCtrl(); | |
// set the set the selectedValue on the drop-down | |
if (selectedValue != null) | |
{ | |
myDropDownCtrl.Items.FindByValue(selectedValue).Selected = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment