ASP.NET 中继器内的 HTML 单选按钮 C#
我试图简单地在中继器内绑定一个 HTML 输入单选按钮:
<asp:Repeater ID="Outlets" runat="server" >
<ItemTemplate>
<input type="radio" name="Proposal" value="Test1" id="Radio1" checked="
<%#`GetSelectedValue(DataBinder.Eval(Container.DataItem,"IsDefaultSelection"))%>" />`
<label for="Test1">
<%#DataBinder.Eval(Container.DataItem, "Label")%>
</label>
</ItemTemplate>
</asp:Repeater>
GetSelectedValue 方法只是返回一个字符串“checked”以选择单选按钮,假设中继器有 3 个项目要循环,并且标记何时呈现,如果我检查元素,我看到第一个单选按钮的正确值,即检查=“检查”,但在用户界面上,第三个单选按钮被选中,即使其检查值=“假”,有人可以指导我我做错了什么吗?
I am trying to simply bind a HTML Input radio button inside a repeater :
<asp:Repeater ID="Outlets" runat="server" >
<ItemTemplate>
<input type="radio" name="Proposal" value="Test1" id="Radio1" checked="
<%#`GetSelectedValue(DataBinder.Eval(Container.DataItem,"IsDefaultSelection"))%>" />`
<label for="Test1">
<%#DataBinder.Eval(Container.DataItem, "Label")%>
</label>
</ItemTemplate>
</asp:Repeater>
The GetSelectedValue method simply returns a string "checked" for the radio button to be selected, lets say the repeater had 3 items to loop and when the markup renders and If I inspect the element I see the correct value for the first radio button i.e. checked="checked" but on the UI the 3rd radio button gets selected even though its checked value="false", can someone guide me as to what i am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
基本上,包含
checked
属性会导致RadioButton
被检查。你想把它拉出来,这样整个东西就会被渲染出来,或者整个东西就会消失。另请记住,您的所有
RadioButton
都将被命名为Test1
使用服务器端RadioButton
可能是个好主意。Give this a try
Basically the inclusion on the
checked
attribute is causing theRadioButton
to be checked. You want to pull it out so the entire thing is rendered or the entire thing is absent.Also keep in mind all your
RadioButtons
are going to be namedTest1
It might be a good idea to use a server sideRadioButton
.HTML 中的 CHECKED 属性没有与之关联的值。仅当您想选择该属性时才应该使用它。
您想要类似的东西:
否则您可以简单地使用 ASP.NET INPUT 控件。
The CHECKED attribute in HTML has no value associated with it. You should only use this attribute if you want to select it.
You want something like:
Otherwise you could simply use the ASP.NET INPUT controls.