Set value property of RadioButton(设置 RadioButton 的 value 属性)
问题描述
我需要根据从数据库返回的数据构建单选按钮列表.每个按钮都需要有一个与之关联的值,我可以根据选定的按钮退出.
I need to built a list of radio buttons, based on data I return from my DB. Each button needs to have a value associated with it that I can get out based on the selected button.
理想情况下,我只使用 RadioButtonList 控件,但是,我需要一个非常自定义的布局,而 RadioButtonList 似乎无法处理.
Ideally I would just use the RadioButtonList control, however, I need to have a very custom layout which a RadioButtonList doesn't appear to be able to handle.
另一种方法是创建单独的 RadioButton 并将它们包装在 Panel 中以将它们分组.但是,RadioButton 上似乎没有 Value 属性?
An alternative would be to create individual RadioButtons and wrap them in a Panel to group them. However, there doesn't appear to be a Value property on a RadioButton?
是否有另一种方法可以为 RadioButton 控件设置值?或者,一种完全自定义 RadioButtonList 输出的方法.
Is there an alternative way to set a value to a RadioButton control? Alternatively, a way to completely customise the RadioButtonList output.
目前,我想我可能不得不求助于使用带有 runat="server" 的 HTML 单选按钮,一定是更好的方法...?
At the moment, I'm thinking I might have to resort to using HTML radio buttons with runat="server", must be a better way...?
推荐答案
您可以创建自己的单选按钮类,扩展标准单选按钮类并添加 value 属性:
You could create your own radio button class which extends the standard one and adds a value property:
public class ValueCheckBox : System.Web.UI.WebControls.RadioButton
{
public string Value { get; set; }
}
这篇关于设置 RadioButton 的 value 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:设置 RadioButton 的 value 属性
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
