0
I have a static multiple Dropdownlist (ddl1) on my aspx page. It has 4 options, in which you can select from 0 to 4 options. Another Dropdownlist (ddl2) that is also static in the form has the Onselectedindexchanged event and when this event is triggered dll1 loses the multiple selections, keeping only the first option selected (or none if the user does not select).
<!-- 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 just updates the grid on the screen, no interaction with ddl’s.
What should I do to keep ddl1 items selected after events are triggered? Remembering that ddl is not loaded dynamically, so 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();
}
Where is code Behind?
– Leandro Angelo
The Behind code is quite dry yet. It only makes a query on the bench and plays in a Gridview. The only part that one of the ddls appears in the code is the following:
GridPrincipal.PageSize = int.Parse(dpBuscaPageSize.SelectedItem.Text)
Postback calls nothing. Load() is called only when it is ! isPostBack, which in turn throws the dice into Gridview and gave. I believe there is no relevance to this case. ddl2 change calls Load() also.– Veber
but it has its load and the event that is firing the postback...
– Leandro Angelo
Ready. I haven’t made the filters yet because this ddl is not behaving as it should, when finishing the screen then yes I do the functional part
– Veber