asp:选择dropdownlist.SelectedItem作为SQL WHERE条件

asp:选择dropdownlist.SelectedItem作为SQL WHERE条件,sql,asp.net,Sql,Asp.net,如何在SqlDataSource中正确设置sql语句 <asp:DropDownList ID="customersDropDownList" runat="server" DataSourceID="customerSqlDataSource" DataTextField="KLIENT" DataValueField="KLIENT"> <asp:ListItem>Klient</asp:ListItem> </asp:DropDownList>

如何在SqlDataSource中正确设置sql语句

<asp:DropDownList ID="customersDropDownList" runat="server" DataSourceID="customerSqlDataSource" DataTextField="KLIENT" DataValueField="KLIENT">
<asp:ListItem>Klient</asp:ListItem>
</asp:DropDownList>

克利特


试试下面的方法

<asp:SqlDataSource ID="projektSqlDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:pd1960ConnectionString %>"
    SelectCommand="SELECT DISTINCT cast(PROJECT AS VARCHAR) + 
': ' + OPIS AS ProjektOPIS FROM [V_works] 
WHERE ([KLIENT]=@Customer">
    <SelectParameters>
        <asp:ControlParameter ControlID="customersDropDownList" PropertyName="SelectedValue"
            Name="Customer" Type="String" DefaultValue="Klient" />
    </SelectParameters>
</asp:SqlDataSource>


并且,确保在下拉控件中设置了
AutoPostBack=“True”

确保在下拉列表中将属性AutoPostBack设置为True。您遇到了什么错误?
<asp:SqlDataSource ID="projektSqlDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:pd1960ConnectionString %>"
    SelectCommand="SELECT DISTINCT cast(PROJECT AS VARCHAR) + 
': ' + OPIS AS ProjektOPIS FROM [V_works] 
WHERE ([KLIENT]=@Customer">
    <SelectParameters>
        <asp:ControlParameter ControlID="customersDropDownList" PropertyName="SelectedValue"
            Name="Customer" Type="String" DefaultValue="Klient" />
    </SelectParameters>
</asp:SqlDataSource>