I have a dropdown list in my form . After submitting the form I don't get selected value from the dropdown list in UI. I only get first value . How to implement this . How to display dropdown selected value after form submit .
You need to use ViewState or Sessions to save the variable and reuse it, It would look something like this:
private void Page_Load()
{
//If page is not being loaded for first time then set the value another
//option would be to check if ViewState["dropdownvalue"] == null and if
//not then set the value
if (Page.IsPostBack)
{
DropDownList1.SelectedValue = ViewState["dropdownvalue"]
}
}
protected void Submit_Click(object sender, EventArgs e)
{
ViewState["dropdownvalue"] = DropDownList1.SelectedValue;
// Do everything else
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.