如何找到检查单选直放站项目里面呢? [英] How to find checked RadioButton inside Repeater Item?

查看:95
本文介绍了如何找到检查单选直放站项目里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样定义的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;
    }
}

但希望能以某种方式simplier做(也许通过LINQ的对象)。

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.

您的服务器code随后将刚刚从隐藏字段访问选择的值。

Your server code would then just access the selected value from the hidden field.

这篇关于如何找到检查单选直放站项目里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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