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 属性
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
