【发布时间】:2011-05-18 18:58:02
【问题描述】:
我有一个 GridView,在它的 OnRowDataBound 回调中我正在添加一个新单元格,我正在向该单元格添加一个 RadioButton。我已经在单选按钮上设置了 GroupName,但我仍然可以一次选择多个按钮。
如何将它们分组,以便在组中只能选择一个单选按钮。
编辑 - 这是我的代码:
// Add the radio button to select if this purchased address
// is set the the home address of the contact
e.Row.Cells.AddAt(0, new TableCell());
RadioButton rbSetAddress = new RadioButton();
rbSetAddress.ID = "rdSetAddress" + e.Row.Cells[2].Text;
rbSetAddress.GroupName = "SetAddress";
e.Row.Cells[0].Controls.Add(rbSetAddress);
所以我设置了一个唯一的 ID 和相同的 GroupName。 ASP.NET 没有将输入的名称属性设置为 GroupName。所以我可以选择任意数量的单选按钮。这不是我想要发生的。我希望能够在由 GroupName 标识的组中选择一个且仅一个。
【问题讨论】:
标签: c# asp.net-2.0 radio-button