How to find checked RadioButton inside Repeater Item?

泪湿孤枕 提交于 2019-11-30 09:11:25

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.

You could always use Request.Form to get the submitted radio button:

var value = Request.Form["answerVariants"];

I think the submitted value defaults to the id of the <asp:RadioButton /> that was selected, but you can always add a value attribute - even though it's not officially an <asp:RadioButton /> property - and this will then be the submitted value:

<asp:RadioButton ID="answerVariantRadioButton" runat="server"
    GroupName="answerVariants" 
    Text='<%# DataBinder.Eval(Container.DataItem, "Text")%>'"
    value='<%# DataBinder.Eval(Container.DataItem, "SomethingToUseAsTheValue")%>' />

I'm pretty sure that the only thing you could use LINQ to Objects for here would be to take the conditions from within the foreach loop and move them to a where clause.

RadioButton checked = 
    (from item in answerVariantRepeater.Items
    let radioButton = (RadioButton)item.FindControl("answerVariantRadioButton")
    where radioButton.Checked
    select radioButton).FirstOrDefault();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!