asp.net – 转发器控件中的单选按钮列表
发布时间:2020-05-22 16:43:21 所属栏目:asp.Net 来源:互联网
导读:我的页面中有一个转发器控件.在检查单选按钮时,我需要在所有行(项目模板)中都有一个单选按钮,其余的单选按钮必须取消选中. 这该怎么做? 提前致谢, 托尔 不幸的是,在Repeater中使用时,GroupName属性不能按预期工作,这是一个已知错误( http://support.microsof
|
我的页面中有一个转发器控件.在检查单选按钮时,我需要在所有行(项目模板)中都有一个单选按钮,其余的单选按钮必须取消选中. 这该怎么做? 提前致谢, 解决方法不幸的是,在Repeater中使用时,GroupName属性不能按预期工作,这是一个已知错误( http://support.microsoft.com/kb/316495).问题是Repeater实现了INamingContainer接口,该接口要求所有嵌套控件在呈现为HTML时具有唯一名称.这会导致单选按钮中断,因为为了使它们正常工作,它们必须具有相同的名称.我遇到过两种解决方法: 1 – 第一个是客户端javascript解决方案.它由Microsoft support提供.或者更容易阅读的版本here. function SetUniqueRadioButton(nameregex,current)
{
re = new RegExp(nameregex);
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i]
if (elm.type == 'radio')
{
if (re.test(elm.name))
{
elm.checked = false;
}
}
}
current.checked = true;
}
现在该函数需要链接到转发器的OnDataItemBound事件中的单选按钮.将“RadioButton”替换为RadioButton控件的名称,将“RadioGroup”替换为您选择的GroupName: protected void Repeater1_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return;
RadioButton rb = (RadioButton) e.Item.FindControl("RadioButton");
string script = "SetUniqueRadioButton('Repeater1.*RadioGroup',this)";
rb.Attributes.Add("onclick",script);
}
2 – 第二个解决方案是使用继承自RadioButton的自定义用户控件的服务器端解决方案.教程和源代码可以在这里下载:http://www.codeproject.com/KB/webforms/How_group_RButtons.aspx (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 剃刀 – Telerik Kendo MVC TextBox多线模式
- 数组 – 如何在vbscript中实现具有可变大小的数组
- ASP.NET AJAX日历扩展程序日期格式
- asp.net-mvc – 双值绑定问题
- asp.net – ASP .NET核心Cookie身份验证到期时返回时从时间
- 如何以编程方式在ASP.NET MVC中显示/隐藏Razor View中的一个
- asp.net – IE 11中的报表查看器打印按钮
- asp.net-mvc – 具有错误的剃刀语法编译时不应该编译
- asp.net-mvc – 如何使@ Html.EditorFor禁用
- asp.net-mvc-3 – MVC将JSON ViewModel传递给View
推荐文章
站长推荐
- 体验使用gcServer =“true”为.NET设置垃圾回收器
- asp.net-mvc – 双值绑定问题
- 如何在ASP.NET中设置TextBox中的对齐中心?
- asp.net-mvc-5 – 在MVC 5的IPasswordStore中,Se
- asp.net – 如何在WebPage中显示嵌入的Excel文件
- asp.net-web-api – 如何设置Elmah与ASP.NET Web
- asp.net-mvc-4 – 带有TextBoxFor的MVC在循环中具
- 如何知道asp.net 3.5 sp1和asp.net mvc是否安装在
- .net – 在控制器中创建子文件夹
- asp.net – 在IIS中,为什么窗口验证不显示为我的
热点阅读
