簡體   English   中英

根據用戶輸入填充/刷新下拉列表

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

我正在一個asp.net應用程序上。 我有一個客戶帳號的下拉列表。 當我在文本框中輸入客戶身份證號並單擊“搜索”按鈕時,下拉列表中應填充先前針對該身份證號提供的所有帳號。 它工作正常,但是當我添加新的身份證號並單擊“搜索”時,下拉列表仍保留先前客戶的帳號。 我希望下拉菜單為空並在每次單擊“搜索”時重新排列,並且值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 /> 

我正在使用UL.GetAccountNO()函數用查詢填充ddl。 如果用戶選擇其他,則將顯示一個文本框,用戶可以在其中輸入帳號(下拉菜單中的帳號)。

粘貼示例代碼:

設計:

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

背后的代碼:

    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