简体   繁体   中英

Retrieve values from dynamic radiobuttonlist

I have a table that has 3 columns. In the 3rd column there is a radiobuttonlist that the user uses to evaluate the similarity of columns 1 and 2. The table has 60+ rows and is created dynamically. All of that works like a charm. BUT: How can I read the radiobuttonlist (or rather the values that the user chose) after the submit? I have tried the following, but that doesn't work (all of which is in a form of course):

eval1 = new RadioButtonList();
eval1.Items.Add(new ListItem("Agree","1"));
eval1.Items.Add(new ListItem("Somewhat Agree","2"));
eval1.Items.Add(new ListItem("Disagree","3"));
eval1.Attributes.Add("runat", "server");
this.Session["eval1"] = eval1;

When I submit this, the session var holds the radionbuttonlist, but no value is selected.

I tried to set AutoPostBack to true and that changed the behavior to what I need. But I don't want to reload the page every time the user chooses an option. This would mean 60+ reloads...

Any hints?

in place of:

this.Session["eval1"] = eval1;

use string array to store the values in the session.

This code is placed where?Maybe you should put it in the if (! IsPostBack ) {} try。For example

if(!IsPostBack)
{
      eval1 = new RadioButtonList();
      eval1.Items.Add(new ListItem("Agree","1"));
      eval1.Items.Add(new ListItem("Somewhat Agree","2"));
      eval1.Items.Add(new ListItem("Disagree","3"));
      eval1.Attributes.Add("runat", "server");
      this.Session["eval1"] = eval1;

}

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