我可以将不是 ListItems 的控件添加到 RadioButtonList 中吗?
我需要提供一种方法来允许用户选择 1 个主题,但这些主题被分组为资格,因此我想为每个“组”显示一个标题。我的第一个想法是 asp:RadioButtonList,因为它提供了一个选项列表,从中只能选择一个,但无法添加标题来分解列表。
所以我尝试了以下代码 - 但我看不到正在添加 LiteralControl,这让我认为这不是一个有效的方法。
For Each item As Subject In Qualifications
If item.QualCode <> previousQualCode Then
rblSelection.Controls.Add(New LiteralControl(item.QualName))
End If
rblSelection.Items.Add(New ListItem(item.SubjectName, item.SelectionCode))
previousQualCode = item.QualCode
Next
I need to provide a way to allow users to select 1 Subject, but the subjects are grouped into Qualifications and so I want to show a heading for each 'group'. My first thought is an asp:RadioButtonList as that provides a list of options from which only one can be selected but there's no means to add break the list up with headings.
So I tried the following code - but I can't see that the LiteralControl is being added, which makes me think it's not a valid approach.
For Each item As Subject In Qualifications
If item.QualCode <> previousQualCode Then
rblSelection.Controls.Add(New LiteralControl(item.QualName))
End If
rblSelection.Items.Add(New ListItem(item.SubjectName, item.SelectionCode))
previousQualCode = item.QualCode
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能这样做。仅具有ListItems才有效。另一种方法是为每个主题设置一个 RadioButton。为它们提供相同的组名,这意味着您只能设置一个,但您可以在页面上(也许在标题下)按照您喜欢的方式排列它们。
代码隐藏:
在您的情况下,使用占位符控件并将动态生成的控件和标头添加到占位符控件集合中。
No you can't do this. It is only valid to have ListItems. Another approach would be to have a RadioButton for each subject. Give them all the same GroupName which will mean you can only set one, but you can arrange them however you like on the page, under headings, maybe.
Code Behind:
In your case, use a placeholdercontrol and add the dynamically generated controls and headers to the placeholders Controls collection.