简体   繁体   English

如何创建数量有限的预配置DropDownList和文本框

[英]How to create a limited number of pre-configured DropDownList and Textbox

I'm trying to create in a repeater a DropDownList and a TextBox for simulating a typical question list 我正在尝试在转发器中创建一个DropDownList和一个TextBox以模拟典型的问题列表

My question is, how can I create 5 rows in my repeater with this dropdownlists and textboxes 我的问题是,如何使用此下拉列表和文本框在中继器中创建5行

Q: DropDownList1 A: TextBox1 问:DropDownList1答:TextBox1

Q: DropDownList2 A: TextBox2 问:DropDownList2答:TextBox2

Q: DropDownList3 A: TextBox3 问:DropDownList3答:TextBox3

Q: DropDownList4 A: TextBox4 问:DropDownList4答:TextBox4

Q: DropDownList5 A: TextBox5 问:DropDownList5答:TextBox5

Another day we could change the number of questions to 3, so my repeater should bind 3 QA 改天,我们可以将问题数量更改为3,因此我的中继器应绑定3个质量检查

How can I do this dynamically. 我该如何动态地做到这一点。

I create the structure like this... but I don't know how to begin the Load event in order to render as I said before. 我创建这样的结构...但是我不知道如何开始Load事件以进行渲染,就像我之前说的那样。

<asp:Repeater ID="repeater1" runat="server">
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <asp:DropDownList ID="ddlQuestion" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="txtAnswer" runat="server" />
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Easiest way might be to encapsulate those low-order controls in a higher order control (namely an ASCX) and then add that to the placeholder in a loop. 最简单的方法可能是将那些低阶控件封装在一个高阶控件(即ASCX)中,然后将其添加到循环中的占位符中。 This way you get the benefit of being able to easily change the ASCX without repercussions on the outer looping code. 这样,您将获得能够轻松更改ASCX的好处,而不会影响外部循环代码。

Edit: "adding" means creating the controls and then attaching them as children. 编辑:“添加”是指创建控件,然后将其附加为子控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM