2016-12-07 20 views
0

SqlDataSourceから読み込まれたリストビューがあります。クエリ文字列のカテゴリ値に基づいて、データベースの製品リストを表示します。商品表のカテゴリはNew|Fiction|Auto|Textです。どのように私はすべてのカテゴリを表示するデフォルト値を設定することができます。カテゴリはDropdownListから選択されています。ドロップダウンリストでALLを選択すると、すべての製品を表示する必要があります。複数の既定値をSqlDataSourceに設定する条件

のDropDownList

<asp:DropDownList runat="server" id="ddl" OnSelectedIndexChanged="SelectionChanged" AutoPostBack="true"> 
     <asp:ListItem Text="All" ></asp:ListItem> 
     <asp:ListItem Text="Fiction" Value="~/Bio.aspx?Category=Fiction" /> 
     <asp:ListItem Text="TextBooks" Value="~/Bio.aspx?Category=Text" /> 
     <asp:ListItem Text="Biography" Value="~/Bio.aspx?Category=Auto" /> 
     <asp:ListItem Text="New Release" Value="~/Bio.aspx?Category=New" /> 
    </asp:DropDownList> 


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:2016_675_z1787626ConnectionString %>" SelectCommand="SELECT * FROM [Bio] WHERE ([Category] = @Category)" > 
     <SelectParameters> 
      <asp:QueryStringParameter Name="Category" QueryStringField="Category" Type="String" /> 
     </SelectParameters> 
</asp:SqlDataSource> 

答えて

0

あなたはselect文にwhere句を変更する必要があります。

<asp:DropDownList runat="server" id="ddl" 
    OnSelectedIndexChanged="SelectionChanged" 
    AutoPostBack="true"> 
    <asp:ListItem Text="All" Value="~/Bio.aspx?Category=ALL" ></asp:ListItem> 
    ... 
</asp:DropDownList> 

SELECT * FROM [Bio] WHERE (@Category = '' OR @Category = 'ALL' OR [Category] = @Category) 
関連する問題