Load Fields through Dropdownlist

Asked

Viewed 59 times

0

I am with a dropdownlist (cbrecipes) that is loaded through the Sqldatasource, where after loaded the of cbrecipes, it loads the cbplanos through the 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 you load cbReceitas, which automatically loads cbPlanos, I need you to make some changes to the textbox, with this code:

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

Except it only works if I click on plans and change. The foreground that loads does not change the textbox, in all events that I place does not work, only if I click and change the second and return to the first. In which event I can do, to click together with the Sqldatasource?

1 answer

0


marianac_costa,

You can make this change in the grid 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 along those lines.

  • I’ll take the test and come back to report what happened.

  • You ran the tests?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.