如何动态创建面板和单选按钮

如何动态创建面板和单选按钮

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

问题描述

请问如何创建选择题页面.我希望从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

推荐答案

<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..


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!
:)


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

07-25 17:29