如何动态创建面板和单选按钮 [英] how to dynamically create panels and radiobuttons

查看:70
本文介绍了如何动态创建面板和单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问如何创建选择题页面.我希望从xml文件中加载问题和选项.

pls how can i create a multiple choice questions page.i want the questions and options to be loaded from an xml file.help me out

推荐答案

对于WebForms
嗨......
您可以为此使用数据列表:

For WebForms
hi....
u can use datalist for this:

<asp:DataList ID="dl" runat="server">
            <ItemTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:Label ID="lblQues" runat="server" Text="Question" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:RadioButtonList ID="rbtOptions" runat="server">
                                <asp:ListItem Text="Option A" Value="a" />
                                <asp:ListItem Text="Option B" Value="b" />
                                <asp:ListItem Text="Option C" Value="c" />
                                <asp:ListItem Text="Option D" Value="d" />
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>




那么您可以提供DataList的数据源并在"OnItemDataBound"事件中绑定文本和值.




then u can give datasource of DataList and bind texts and values in "OnItemDataBound" event..


对于WinForms
如果您使用usercontrol会很容易
只需创建一个用户控件,其中带有问题"的标签,以及四个带有答案的单选按钮

现在,只需在表单运行时添加此用户控件

假设用户控件名称为MyQAControl
现在,只需以表格形式添加此控件

在表单运行时添加控件的代码
For WinForms
It will be easy if you go with usercontrol
just create one user-control having label for Question and four radiobuttons for answer

now, just add this user control in form run time

suppose usercontrol name is MyQAControl
now, just add this control in form

Code to add control on form runtime
MyQAControl QA = new MyQAControl(); //create object of control/panel/radiobutton
QA.Dock = Top; //set location using dock or location property
this.Controls.Add(QA); //add control into form so you will able to see that on form



如果您要添加单选按钮&面板没有用户控制,然后以我为"MyQAControl"制作的相同方式创建面板对象.
并且您应该管理控件运行时的位置.

祝您编码愉快!
:)



if you want to add radiobuttons & panels saperately without usercontrol then create object of panel same way I have make for ''MyQAControl''.
And you should manage location of control runtime.

Happy Coding!
:)


这篇关于如何动态创建面板和单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆