Load Fields via DropDownList

0

I have a dropdownlist (cbreceitas) which is loaded through SqlDataSource, where after loading the cbreceitas, it loads the cbplanos through SqlDataSouce, follows the code:

<div class="grid-9">
  <asp:Label ID="Label8" runat="server" Text="Receita"></asp:Label>
  <asp:DropDownList ID="cbReceitas" runat="server" class="form-control" DataSourceID="SqlReceitas" DataTextField="descricao" DataValueField="id" AutoPostBack="True" OnSelectedIndexChanged="cbReceitas_SelectedIndexChanged" CssClass="form-control"></asp:DropDownList>
  <asp:SqlDataSource ID="SqlReceitas" runat="server" SelectCommand="select id, descricao from plano_contas where tipo = 'R' order by [descricao] asc" OnInit="SqlReceitas_Init" OnLoad="SqlReceitas_Load"></asp:SqlDataSource>
</div>
<div class="grid-9">
  <asp:Label ID="Label9" runat="server" Text="Planos"></asp:Label>
  <asp:DropDownList ID="cbPlanos" runat="server" DataSourceID="SqlPlanos" DataTextField="descricao" DataValueField="id" OnSelectedIndexChanged="cbPlanos_SelectedIndexChanged" AutoPostBack="True" CssClass="form-control" OnDataBinding="cbPlanos_DataBinding"
    OnLoad="cbPlanos_Load" OnTextChanged="cbPlanos_TextChanged"></asp:DropDownList>
  <asp:SqlDataSource ID="SqlPlanos" runat="server" SelectCommand="SELECT [id], [descricao] FROM [servicos] WHERE ([plano_id] = @plano_id) order by [descricao] asc" OnInit="SqlPlanos_Init" OnLoad="SqlPlanos_Load">
    <SelectParameters>
      <asp:ControlParameter ControlID="cbReceitas" Name="plano_id" PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
  </asp:SqlDataSource>
</div>

When I load cbReceitas, which automatically loads cbPlans, I need to make some changes to the textbox, with this code:

Nome_Pessoa();
Valor_serviço();
txtHistorico_desta.InnerText = cbReceitas.SelectedItem + "(" + cbPlanos.SelectedItem + ")" + " - " + aluno_nome;

Only it only works if I click on cbplanos and mute. The first plane that loads does not change the textbox, in all the events that I put does not work, only if I click and change of the second and return to the first one. In what event can I do, so that it loads along with the SqlDataSource?

    
asked by anonymous 01.12.2017 / 18:35

1 answer

0

marianac_costa,

You can make this change in the grid's ItemDataBound.

   void Item_Bound(Object sender, DataGridItemEventArgs e) 
   {
      if (e.Item is GridDataItem)
      {
           txtHistorico_desta.InnerText = cbReceitas.SelectedItem + "(" + cbPlanos.SelectedItem + ")" + " - " + aluno_nome;
      }
   }

I believe something like this works.

    
07.12.2017 / 12:31