I have a static Multiple DropDownList (ddl1) on my aspx page. It has 4 options, from which 0 to 4 options can be selected. Another DropDownList (ddl2) that is also static on the form has the OnSelectedIndexChanged event and when this event is triggered, dll1 loses multiple selections, keeping only the first option selected (or none if the user does not select it).
<!-- ddl1: -->
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="PanelPesquisa" runat="server" CssClass="form-group">
<!-- [...] Alguns Campos de Busca [...] -->
<asp:DropDownList ID="dpBuscaEtapasCapacitacao" runat="server"
CausesValidation="false" ValidationGroup="BuscarQuestao"
ClientIDMode="Static" CssClass="chosen-select form-control" data-
placeholder="Selecione as Etapas" multiple="multiple" TabIndex="4">
<asp:ListItem Text="Nivelamento" Value="0"></asp:ListItem>
<asp:ListItem Text="Capacitação EaD" Value="1"></asp:ListItem>
<asp:ListItem Text="Capacitação Presencial" Value="2">
</asp:ListItem>
<asp:ListItem Text="Atualização" Value="3"></asp:ListItem>
</asp:DropDownList>
<!-- ddl2: -->
<asp:DropDownList ID="dpBuscaPageSize" runat="server" CssClass="form-
control" AutoPostBack="true" CausesValidation="true"
OnSelectedIndexChanged="BuscaDados" ClientIDMode="Static">
<asp:ListItem Text=""></asp:ListItem>
<asp:ListItem Text="5"></asp:ListItem>
<asp:ListItem Text="10"></asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<!-- [...] Muito HTML depois [...] -->
</ContentTemplate>
</asp:UpdatePanel>
The event only updates the grid on the screen, without interaction with ddl's.
What should I do to keep ddl1 items selected after events are triggered? Remembering that ddl is not loaded dynamically, then there is no way I can "call the function in postback" because there is no function.
Code Behind:
protected override void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
CarregaDados();
}
private void CarregaDados(){
var lst = consulta_no_banco(" - sql_query - ");
GridPrincipal.PageSize = int.Parse(dpBuscaPageSize.SelectedItem.Text);
GridPrincipal.DataSource = lst;
GridPrincipal.DataBind();
}
/*
Esta função é chamada em todos os eventos dos Controls de filtro da tela.
Cada TextChanged e SelectedItemChanged do filtro é direcionado para cá, mas
ainda não estou fazendo o filtro em sí.
*/
protected void BuscaDados(object sender, EventArgs e)
{
CarregaDados();
}