Pregunta

I have this asp in a formview insert template.

  <asp:FormView ID="FormViewReport" runat="server">
  <InsertItemTemplate>
     GAME_ID:
        <asp:DropDownList ID="DropDownListReportIns" runat="server" AutoPostBack="true"
            DataSourceID="SqlDataSourceGetGame"
            DataTextField="GAME" DataValueField="ID" SelectedValue='<%# Bind("GAME_ID") %>' AppendDataBoundItems="True">
            <asp:ListItem Text="ΠΑΡΑΚΑΛΩ ΕΠΙΛΕΞΤΕ ΑΓΩΝΑ" />
        </asp:DropDownList>
     HOME_PLAYER:
        <asp:DropDownList ID="DropDownListRepo" runat="server"
            DataSourceID="SqlDataSourceGetPlayers"
            DataTextField="HOME_PLAYER_S" DataValueField="HP_ID" SelectedValue='<%# Bind("HOME_PLAYER_ID") %>' >
        </asp:DropDownList>

The sql datasource of the second dropdownlist:

      <asp:SqlDataSource ID="SqlDataSourceGetPlayers" runat="server" ConnectionString='<%$ ConnectionStrings:BasketballConnectionString1 %>' SelectCommand="SELECT HP.SURNAME  blah blah blah WHERE (GAMES.ID = @GAME_ID)">
    <SelectParameters>
        <asp:ControlParameter ControlID="FormViewReport" PropertyName="SelectedValue" Name="GAME_ID"></asp:ControlParameter>
    </SelectParameters>

In the second Dropdownlist the query needs the GAME_ID parameter and this is the DatavalueField of the first dropdownlist.How I can get the selected value from the first dropdownlist and give it to the second dropdownlist?

¿Fue útil?

Solución 2

Finally I did it using asp for the second dropdownlist:

 <asp:DropDownList ID="DropDownListRepIns" runat="server"    AppendDataBoundItems="True" EnableViewState="false" 
            DataSourceID="SqlDataSourceGetPlayers"
            DataTextField="HOME_PLAYER_S" DataValueField="HP_ID" >
                           <asp:ListItem Text="ΠΑΡΑΚΑΛΩ ΕΠΙΛΕΞΤΕ ΑΓΩΝΑ" Value="0" />
         </asp:DropDownList><br />

and a c# code for event item inserting that binds manually:

       protected void FormViewReport_ItemInserting(object sender, FormViewInsertEventArgs e)
{
    e.Values["HOME_PLAYER_ID"] = ((DropDownList)((FormView)sender).FindControl("DropDownListRepIns")).SelectedValue;}

Also the solution this solution works without needing code behind:

  SelectedValue='<%# DataBinder.Eval (Container.DataItem, "HOME_PLAYER_ID") %>'

You have to use this in the second dropdownlist in asp.

Otros consejos

Put your SqlDatasource control inside the InsertItemTemplate of your FormView (with the DropDownLists), and then change it to this:

<asp:SqlDataSource ID="SqlDataSourceGetPlayers" runat="server" ConnectionString='<%$ ConnectionStrings:BasketballConnectionString1 %>' SelectCommand="SELECT HP.SURNAME  blah blah blah WHERE (GAMES.ID = @GAME_ID)">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownListReportIns" PropertyName="SelectedValue" Name="GAME_ID"></asp:ControlParameter>
    </SelectParameters>
</asp:SqlDataSource

That way your ControlParameter is referencing the selected value of the 1st drop down.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top