如何设置使用ASP.Net无线电输入标签检查的价值? [英] How to set checked value for a radio input tag using ASP.Net?

查看:116
本文介绍了如何设置使用ASP.Net无线电输入标签检查的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种无线电标签:

<input name="phoneRadio" class="phoneRadio" id="rbDefaultPhone" 
    type="radio" checked="<%# GetIsChecked(Eval("IsDefault")) %>"/>

在一个中继器和GetIsChecked是一个C#函数返回bool值,我的问题,即它不影响单选按钮的正确方法的检验值,
任何一个知道如何解决这个问题?

in a repeater and GetIsChecked is a c# function which return bool value, my problem that its not affecting the checked value of the radio button the right way, Any one know how to fix that?

推荐答案

就具有检查输入属性是足以使它检查。在HTML中,你只需要拥有在那里检查,在XHTML中,它应该是检查=选中,但无论哪种方式,你要排除整个属性,如果未选中它。

Just having the checked attribute on the input is enough to make it checked. In HTML, you just need to have checked in there, in XHTML, it should be checked="checked", but either way, you'll want to exclude the whole attribute if it isn't checked.

这就是 GetIsChecked 应(改名和)返回或者检查='检查'。的String.Empty 。然后,您将调用它只是在输入标签本身,而不是作为的值检查属性(你应该删除)。它会是这个样子:

That is, GetIsChecked should (be renamed and) return either "checked='checked'" or String.Empty. You will then call it just in the input tag itself, not as the value for the checked attribute (which you should remove). It'll look something like this:

<input name="phoneRadio" class="phoneRadio" id="rbDefaultPhone" type="radio" <%# GetChecked(Eval("IsDefault"))%> />

&NBSP;

protected string GetChecked(object isDefault)
{
    return (bool)isDefault ? "checked='checked'" : string.Empty;
}

这篇关于如何设置使用ASP.Net无线电输入标签检查的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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