我正在尝试动态输入下拉菜单中的值,然后再获取它们。它可以正常运行,但是一旦我添加了默认选项,所有的一切都会变得一团糟。无论我从下拉菜单中选择什么,它都会选择默认选项defacto。有人可以建议我在这里做错什么吗?
<table cellpadding="5" cellspacing="5">
<tr>
<td>
<asp:Label ID="lblBankName" runat="server" Text="Bank Name" Font-Size="13px"></asp:Label>
</td>
<td style="align-content:center">
<asp:DropDownList runat="server" CssClass="form-control input-sm" ID="ddlBankName" Width="200px" OnSelectedIndexChanged="ddlBankName_SelectedIndexChanged" >
</asp:DropDownList>
</td>
<td style="padding-left:5px;">
</td>
<td>
protected void Page_Load(object sender, EventArgs e)
{
//Populate BankName for DropDown List
MSAccessConnection dropdown = new MSAccessConnection();
DataSet output = dropdown.PopulateDropdown("SELECT distinct([Bank]) FROM [BankDetails]");
ddlBankName.DataTextField = output.Tables[0].Columns["Bank"].ToString();
ddlBankName.DataValueField = output.Tables[0].Columns["Bank"].ToString();
ddlBankName.DataSource = output.Tables[0];
ddlBankName.DataBind();
ddlBankName.Items.Insert(0, new ListItem("Select", "All"));
}
答案 0 :(得分:0)
看起来这是因为在页面加载时绑定DropDownList时未使用!IsPostBack条件。尝试下面的代码,它应该可以工作:
dependencies.gradle