RadioButtons 未在 ASP.NET 2.0 中继器中正确分组
我有一个 ASP.NET 2.0 中的 Web 应用程序,其中需要一个高度自定义的网格。网格中的一列包含每行一个单选按钮。
我将其实现为 Repeater
控件,每个 ItemTemplate
中都有一个 div
。问题在于单选按钮(ASP:RadioButton
标记)没有按照应有的方式进行分组;选择其中之一并不会取消选择其余的。我已经在它们上设置了 GroupName
属性,但我没有看到它通过 Firebug 在任何地方的 HTML 中呈现。谷歌搜索告诉我
<input id="{asp_garbage_naming}_ctl01_rbFoo" type="radio"
name="ctl03$controlName$otherControlName$ctl01$name"
value="rbHost" checked="checked" />
有办法让它工作吗?或者我是否必须自己提供单选按钮行为(javascript 等)?
I've got a web app in ASP.NET 2.0 in which I need to have a highly customized grid. One of the columns in the grid contains a radio button for each row.
I'm implementing it as a Repeater
control, with a div
in each ItemTemplate
. The problem is that the radio buttons (ASP:RadioButton
tags) are not being grouped like they should; selecting one of them doesn't deselect the rest. I've set the GroupName
property on them already, but I don't see that being rendered in the HTML anywhere via Firebug. A google search tells me that the "name" attribute on <input type='radio>
is what determines its group membership, but ASP is using that already as some kind of unique identifier. Each radio button looks something like this when rendered to HTML:
<input id="{asp_garbage_naming}_ctl01_rbFoo" type="radio"
name="ctl03$controlName$otherControlName$ctl01$name"
value="rbHost" checked="checked" />
Is there a way to make this work? Or am I going to have to provide radio button behavior on my own (javascript, etc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一位同事遇到了这个问题并实现了一个 jQuery 解决方案。这是它的摘录:
这给了我想要的单选按钮功能,但它阻止我在回发时获取选定的单选按钮。所以我决定手动实现单选按钮功能。
这给了我正确的功能,并且我仍然可以在回发时获取选定的单选按钮和文本框。可能不是最优雅的解决方案,但我找不到任何其他方法来做到这一点。
完整帖子:中继器问题中的单选按钮
A coworker ran across this issue and implemented a jQuery solution. Here's an excerpt of it:
That gave me the radio button functionality that I wanted, but it prevented me from getting the selected radio button on postback. So I decided to just implement the radio button functionality manually.
Which gave me the correct functionality and I could still get the selected radio button and textbox on postback. Probably not the most elegant solution, but I couldn’t find any other way to do it.
Full post: Radio button within a repeater problem
在服务器端执行如下操作:
在 javascript 中执行如下操作
In the server side do as follows:
In the javascript do as follows
问题?您是否需要这些单选按钮作为服务器控件(即您是否需要 runat=server 标签)?如果没有,您可以简单地在列上放置常规 html 单选按钮,并使用
<%#Eval("Property")%>
语法将任何属性绑定到它。只是一个想法Question? Do you need these radio buttons to be server controls (i.e. do you need the runat=server tag)? If not, you could simply have regular html radio buttons on the column and bind any properties to it using the
<%#Eval("Property")%>
syntax. Just a thought