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 属性
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01