简体   繁体   English

在ASP.Net中创建中继器控件

[英]Create a Repeater control in ASP.Net

I'm using two drop down and bind values to that drop down. 我正在使用两个下拉菜单,并将值绑定到该下拉菜单。 Now am adding a new button add_new. 现在正在添加一个新按钮add_new。 I want to create the above drop downs below when I click the add button and maintain the previous selected values. 我想在单击添加按钮并保持先前​​选择的值时在上方创建上述下拉列表。 Please help me to do this. 请帮我做到这一点。

You can achieve the desired result using Repeater control of ASP.Net. 您可以使用ASP.Net的Repeater控件获得所需的结果。 You can create any type of template as you wish, see the code below: 您可以根据需要创建任何类型的模板,请参见以下代码:

ASPX: ASPX:

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" />
        <asp:DropDownList ID="DropDownList2" runat="server" />
        <br />
    </ItemTemplate>
</asp:Repeater>

CodeBehind: 代码隐藏:

protected void Button1_Click(object sender, EventArgs e)
{
    // data fetching logic

    Repeater1.DataSource = data;
    Repeater1.DataBind();
}

Hard to answer without a better explanation and code samples but from experience doing anything with dropdowns over postbacks is better controlled with hidden fields. 如果没有更好的解释和代码示例,很难回答,但是根据经验,通过对回发进行下​​拉操作可以更好地控制隐藏字段。 Set the value of the hidden field with javascript. 使用javascript设置隐藏字段的值。 Please provide more detail. 请提供更多细节。

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

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