Я использовал раскрывающийся список, который заполняется из базы данных при загрузке страницы. Я хочу изменить параметр в зависимости от выбранного варианта в другом раскрывающемся списке. Но когда я выбираю вариант из раскрывающегося списка, тот, который обновляется, исчезает.
Вот код Aspx:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddl2" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<div class="container" style="border: 2px solid black; box-sizing: border-box; border-radius: 20px; padding: 20px">
<p style="font-size: 18px; font-weight: bold; margin-left: 20px">Filter By</p>
<div class="row">
<div class="col">
<p>Department</p>
<asp:DropDownList ID="ddl1" runat="server" data-dropup-auto="false" data-live-search="true" data-live-search-style="startsWith" CssClass="form-control selectpicker" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</div>
<div class="col">
<p>Category</p>
<asp:DropDownList ID="ddl2" runat="server" CssClass="form-control" OnSelectedIndexChanged="ddl2_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="All" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="Goods" Value="tender_goods"></asp:ListItem>
<asp:ListItem Text="Services" Value="tender_services"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="col">
<p>Subject/Item</p>
<asp:DropDownList ID="ddl3" AppendDataBoundItems="False" runat="server" data-dropup-auto="false" data-live-search="true" data-live-search-style="startsWith" CssClass="form-control selectpicker" OnSelectedIndexChanged="ddl3_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Вот C# код
{
if (!IsPostBack)
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from department");
cmd.Connection = con;
MySqlDataReader sdr = cmd.ExecuteReader();
ddl1.DataSource = sdr;
ddl1.DataTextField = "dpt_name";
ddl1.DataValueField = "dpt_id";
ddl1.DataBind();
ddl1.Items.Insert(0, new ListItem("All Departments", "0"));
cmd.Dispose();
MySqlCommand all = new MySqlCommand("select * from goods union all select * from services order by title asc", con);
MySqlDataReader sdr1 = all.ExecuteReader();
ddl3.DataSource = sdr1;
ddl3.DataTextField = "title";
ddl3.DataValueField = "goods_id";
ddl3.DataBind();
ddl3.Items.Insert(0, new ListItem("All Items", "0"));
all.Dispose();
con.Close();
BindGrid();
}
protected void ddl2_SelectedIndexChanged(object sender, EventArgs e)
{
ddl3.Items.Clear();
MySqlConnection conn = new MySqlConnection(constr);
conn.Open();
MySqlCommand all = new MySqlCommand("select * from goods order by title asc", conn);
MySqlDataReader sdr1 = all.ExecuteReader();
ddl3.DataSource = sdr1;
ddl3.DataTextField = "title";
ddl3.DataValueField = "goods_id";
ddl3.DataBind();
ddl3.Items.Insert(0, new ListItem("All Items", "0"));
all.Dispose();
conn.Close();
}
При загрузке страницы:
После выбора опции