【问题标题】:Using a selected item from a DropDownList in a query在查询中使用 DropDownList 中的选定项目
【发布时间】:2017-10-13 05:17:48
【问题描述】:

我正在尝试使用 SELECT 查询中下拉列表中的选定项目。这是我的代码:

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT tblAirport.Name, tblFlight.Destination, tblFlight.FlightDate FROM tblAirport INNER JOIN tblFlight ON tblAirport.AirportCode = tblFlight.AirportCode WHERE Destination = DropDownList1.SelectedItem.Value"></asp:SqlDataSource>

但是,从这段代码中,我在选择项目时遇到错误:

“DropDownList1.SelectedItem.Value”无法绑定。

有人有什么建议吗?

【问题讨论】:

    标签: sql asp.net select drop-down-menu


    【解决方案1】:

    你可以这样做:

    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT tblAirport.Name, tblFlight.Destination, tblFlight.FlightDate FROM tblAirport INNER JOIN tblFlight ON tblAirport.AirportCode = tblFlight.AirportCode WHERE (Destination = @Destination)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="Destination" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      相关资源
      最近更新 更多