简体   繁体   中英

How to reset items in radio button list?

Easy one.

I added programatically a few items to a radiuo button list:

foreach (var item in res)
{
     rbl.Items.Add(new ListItem(item.text, item.value.ToString()));
}

After a change of view (Multiview), I need to come back to the view with the radio button list, but this view added again the items.

How can I reset the items already added to the radio button list?

Used, and not working:

rbl.ClearSelection()

rbl.Datasource = null;
rbl.DataBind();

rbl = new RadioButtonList();

Thanks.

The "ClearSelection()" method simply puts the selection to be "-1", in order to remove the data in the list you will need

RadioButtonList1.Items.Clear();

Also be careful, where you actually add the items, that might cause a problem as well, since I cannot see additional code it is just my prediction.

Hope this solves your problem. Cheers!

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