设置 RadioButton 的 value 属性 [英] Set value property of RadioButton

查看:21
本文介绍了设置 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 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆