[英]How to create a RadioButtonList where each radio button is in a separate table row?
I'm creating an MCQ Question and answer Interface where I need to place my each radio option in separete row next to the answer, so that user can select the answer, I know to use radiobutton list in a single row in normal way, 我正在创建一个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>
but here i need to place them in row by row in an html table as follows, 但是我需要在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>
Here I have used normal radiobuttons, but there is a conflict when getting the selected value, So please any one could suggest a way to use asp:RadioButtonList to do this task? 在这里我使用了普通的radiobuttons,但是在获取所选值时存在冲突,所以请任何人都可以建议使用asp:RadioButtonList来执行此任务?
here I have used normal radiobuttons, but there is a conflict when getting the selected value
在这里我使用了普通的radiobuttons,但在获取所选值时存在冲突
What is conflict? 什么是冲突? why you want to use RAdioButtonList here?
你为什么要在这里使用RAdioButtonList? Your existing code does not show me any conflict.
您现有的代码不会向我显示任何冲突。
You should set RepeatDirection="Vertical"
in order to show the options row-wise. 您应该设置
RepeatDirection="Vertical"
以便按行显示选项。
Please refer my answer @CodeProject - Change ASP radiobuttonlist repeatdirection property with Javascript or JQuery for a more detailed information on how we can toggle between Vertical and Horizontal alignments. 请参考我的答案@CodeProject - 使用Javascript或JQuery更改ASP radiobuttonlist repeatdirection属性,以获取有关如何在垂直和水平对齐之间切换的更详细信息。
Demo - [Demo] Change Repeat Direction of asp RadioButtonList 演示 - [演示]更改asp RadioButtonList的重复方向
EDIT 编辑
Do like below... 如下所示......
<asp:RadioButtonList ID="opt_questiontype" runat="server" RepeatLayout="Flow" RepeatDirection="Vertical" OnClick="call()">
Either use repeater or you can use css to create single row for each radio button. 要么使用转发器,要么可以使用css为每个单选按钮创建单行。
In repeater you can control the HTML as per your requirement 在转发器中,您可以根据您的要求控制HTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.