How to find checked RadioButton inside Repeater Item?(如何在中继器项中找到选中的 RadioButton?)
问题描述
我在 ASPX 页面上有一个 Repeater 控件,定义如下:
I have a Repeater control on ASPX-page defined like this:
<asp:Repeater ID="answerVariantRepeater" runat="server"
onitemdatabound="answerVariantRepeater_ItemDataBound">
<ItemTemplate>
<asp:RadioButton ID="answerVariantRadioButton" runat="server"
GroupName="answerVariants"
Text='<%# DataBinder.Eval(Container.DataItem, "Text")%>'"/>
</ItemTemplate>
</asp:Repeater>
为了允许及时选择一个单选按钮,我使用了一种技巧形式 这篇文章.
To allow select only one radio button in time I have used a trick form this article.
但是现在提交表单时,我想确定选中的是哪个单选按钮.
But now when form is submitted I want to determine which radio button is checked.
我可以这样做:
RadioButton checkedButton = null;
foreach (RepeaterItem item in answerVariantRepeater.Items)
{
RadioButton control=(RadioButton)item.FindControl("answerVariantRadioButton");
if (control.Checked)
{
checkedButton = control;
break;
}
}
但希望它可以以某种更简单的方式完成(可能通过 LINQ to 对象).
but hope it could be done somehow simplier (maybe via LINQ to objects).
推荐答案
由于您已经使用 javascript 来处理客户端上的单选按钮单击事件,您可以同时使用所选值更新隐藏字段.
Since You are using javascript already to handle the radio button click event on the client, you could update a hidden field with the selected value at the same time.
然后,您的服务器代码将只访问隐藏字段中的选定值.
Your server code would then just access the selected value from the hidden field.
这篇关于如何在中继器项中找到选中的 RadioButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在中继器项中找到选中的 RadioButton?


基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01