简体   繁体   English

根据用户输入填充/刷新下拉列表

[英]Populating /Refreshing Drop down list based on user input

I am working on an asp.net application. 我正在一个asp.net应用程序上。 I have a drop down list of customer account no. 我有一个客户帐号的下拉列表。 When i enter customer id card number in text box and click search button, the drop down should be populated with all the account numbers provided against that id card number previously. 当我在文本框中输入客户身份证号并单击“搜索”按钮时,下拉列表中应填充先前针对该身份证号提供的所有帐号。 It works fine but when i add a new id card number and click search the drop down still retains the previous customer's account numbers. 它工作正常,但是当我添加新的身份证号并单击“搜索”时,下拉列表仍保留先前客户的帐号。 I want the drop down to empty and reppulate everytime i click Search and the item at value 1 ie Other should stay constant rest of the list changes dynamically. 我希望下拉菜单为空并在每次单击“搜索”时重新排列,并且值1的项目(即“其他”应保持不变)其余列表会动态更改。

 protected void Search_Click(object sender, EventArgs e) { ddl_accno.Items.Clear(); ddl_accno.Items.Add(new ListItem("Other", "0")); string cnic = txt_cnic.Text; BindControls.ControlBinder.BindDropDown(ddl_accno, UL.GetAccountNo(cnic),"ACCOUNT_NO","ACCOUNT_NO"); } 
 <td style="width:275px"> <label for="textfield"> Account no.</label> <asp:DropDownList Font-Size="Small" ID="ddl_accno" runat="server" AutoPostBack = "True" Width="319px" AppendDataBoundItems="true" onselectedindexchanged="ddl_accno_SelectedIndexChanged"> <asp:ListItem Value="0" Selected="True" Text="Select Account No"></asp:ListItem> <asp:ListItem Value="1" Text="Other"></asp:ListItem> </asp:DropDownList><br /> 

I am using UL.GetAccountNO() function to populate ddl with query. 我正在使用UL.GetAccountNO()函数用查询填充ddl。 If the user selects other a text box will be visible where user can enter an account number apart from the ones in the drop down. 如果用户选择其他,则将显示一个文本框,用户可以在其中输入帐号(下拉菜单中的帐号)。

Pasting a sample code: 粘贴示例代码:

Design: 设计:

<asp:DropDownList ID="AssignedToDropDownList" runat="server" DataSourceID="UserLinqDataSource"
        DataTextField="UserName" DataValueField="UserId" AppendDataBoundItems="true"
        SelectedValue='<%# Bind("AssignedTo") %>'>
    </asp:DropDownList>

Code Behind: 背后的代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        DDLDataBind();
    }

    private void DDLDataBind()
    {
        AssignedToDropDownList.Items.Clear();
        AssignedToDropDownList.Items.Add(new ListItem("--did not assign--", "0"));
        AssignedToDropDownList.DataBind();
    }

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

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