我正在开发一个 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();
}