简体   繁体   English

如何重置单选按钮列表中的项目?

[英]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. 更改视图(Multiview)后,我需要返回带有单选按钮列表的视图,但是此视图再次添加了项目。

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 “ ClearSelection()”方法只是将选择内容设为“ -1”,以便删除列表中的数据,您将需要

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! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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