次のように定義された ASPX ページに Repeater コントロールがあります。
<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>
時間内にラジオ ボタンを 1 つだけ選択できるようにするために、この記事のトリックを使用しました。
しかし、フォームが送信されたときに、どのラジオボタンがチェックされているかを判断したいと思います。
私はこれを行うことができます:
RadioButton checkedButton = null;
foreach (RepeaterItem item in answerVariantRepeater.Items)
{
RadioButton control=(RadioButton)item.FindControl("answerVariantRadioButton");
if (control.Checked)
{
checkedButton = control;
break;
}
}
しかし、それが何とか簡単にできることを願っています(おそらくオブジェクトへのLINQを介して)。