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 RadioButton
s 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 属性


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01