简体   繁体   English

如何创建一个RadioButtonList,其中每个单选按钮位于一个单独的表行?

[英]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.

相关问题 如何为radiobuttonlist创建数据源? - how to create datasource for radiobuttonlist? 选中单选按钮的帖子行 - post row where radio button is checked 如何通过使用C#中的级联下拉菜单选择单选按钮列表中的单选按钮来更改下拉列表值 - how to change dropdownlist values by selecting radio button in the radiobuttonlist using cascading drop down in C# radiobuttonlist中的单选按钮-取消选中不起作用-asp.net-使用jquery - radio button in radiobuttonlist - uncheck not working - asp.net - using jquery 根据从数据库读取的文本值检查RadioButtonList中的单选按钮 - Check radio button in RadioButtonList based on text value read from database 如何使用ActionLink作为提交按钮删除表中的每一行? - How to use ActionLink as submit button to Delete each row in a table? 如何在每个单选按钮上添加变量? - How to add variables on each radio button? 在网格视图的每一行中仅允许检查一个单选按钮 - Allowing only one radio button to be checked in each row of grid view 如何获取单选按钮值并清除表中选中的单选按钮 - How to get radio button value and clear checked radio button in table 如何以编程方式在每行中创建具有不同单元格数量的表? - How to create table with different number of cell in each row programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM