简体   繁体   中英

keep radio button selected across postback

I have a gridview with radio buttons to select a single row. The gridview is populated from a SQL DB according to a value selected from a drop down list. What I want to do is keep the selected radio button when the user moves to a different category, so if he wants to move back via the DDL the value he selected previously is still selected.

What is the best way to do this? The application will have users and I have read sessions could help me with this but I have no idea how it works!

Thanks in advance

I'm not sure really why you'd want to do it this way but you'd then save it in session this way:

String selectedValue = rblYourRadioButtons.SelectedValue;
Session["SelectedRadioButtonValue"] = selectedValue;

Then, on postback or whenever, on the Item Databound of the gridview you check if the current row Id matches the value stored in the session, if it does then select that value in the radiobutton list.

Personally I'd store the value in the DB rather than session.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM