首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多个默认值设置为SqlDataSource其中的条件

问将多个默认值设置为SqlDataSource其中的条件
EN

Stack Overflow用户
提问于 2016-12-07 14:14:41
回答 1查看 229关注 0票数 0

我有一个从SqlDataSource填充的列表视图。它根据查询字符串中的类别值显示数据库中的产品列表。我在产品表中的分类是New|Fiction|Auto|Text。如何设置默认值以显示从category.The中选择的所有DropdownList类别。当我选择所有在下拉列表中,我需要显示所有的产品。

Dropdownlist

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

发布于 2016-12-07 17:37:21

您需要修改select语句中的where子句。

代码语言:javascript
复制
<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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41019690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档