[英]How to create a RadioButtonList where each radio button is in a separate table row?
我正在創建一個MCQ問題和答案界面,我需要將每個無線電選項放在答案旁邊的separete行中,以便用戶可以選擇答案,我知道在正常方式中使用單行的radiobutton列表,
<asp:RadioButtonList ID="opt_questiontype" runat="server" RepeatLayout="Flow" OnClick="call()">
<asp:ListItem Value="MCQ" Selected="True">MCQ</asp:ListItem>
<asp:ListItem Value="Single">Single Answer</asp:ListItem>
</asp:RadioButtonList>
但是我需要在html表中逐行放置它們,如下所示,
<table id="mcqtable">
<tr style="border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#CCCCCC;">
<th class="captions2">Option</th><th class="captions2">Answer Text</th><th class="captions2">Is Correct</th>
</tr>
<tr>
<td class="captions1">Answer Option 1</td><td><asp:TextBox ID="txt_answeropt1" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer1" runat="server" GroupName="grp_answers" Checked="true" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 2</td><td><asp:TextBox ID="txt_answeropt2" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer2" runat="server" GroupName="grp_answers" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 3</td><td><asp:TextBox ID="txt_answeropt3" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer3" runat="server" GroupName="grp_answers" /></td>
</tr>
<tr>
<td class="captions1">Answer Option 4</td><td><asp:TextBox ID="txt_answeropt4" runat="server" TextMode="SingleLine" Width="600px"></asp:TextBox></td><td><asp:RadioButton ID="opt_answer4" runat="server" GroupName="grp_answers" /></td>
</tr>
</table>
在這里我使用了普通的radiobuttons,但是在獲取所選值時存在沖突,所以請任何人都可以建議使用asp:RadioButtonList來執行此任務?
在這里我使用了普通的radiobuttons,但在獲取所選值時存在沖突
什么是沖突? 你為什么要在這里使用RAdioButtonList? 您現有的代碼不會向我顯示任何沖突。
您應該設置RepeatDirection="Vertical"
以便按行顯示選項。
請參考我的答案@CodeProject - 使用Javascript或JQuery更改ASP radiobuttonlist repeatdirection屬性,以獲取有關如何在垂直和水平對齊之間切換的更詳細信息。
演示 - [演示]更改asp RadioButtonList的重復方向
編輯
如下所示......
<asp:RadioButtonList ID="opt_questiontype" runat="server" RepeatLayout="Flow" RepeatDirection="Vertical" OnClick="call()">
要么使用轉發器,要么可以使用css為每個單選按鈕創建單行。
在轉發器中,您可以根據您的要求控制HTML
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.