QueryString -当参数为isn't时显示所有条目
本文关键字:显示 参数 isn QueryString | 更新日期: 2023-09-27 18:02:11
我正在使用Visual Studio和c#,我有一个DataList,显示我拥有的数据库中的游戏。我正在使用QueryString来确定我想要显示的类型(类别)。
DataList是用游戏标题和图像填充的,我的SqlDataSource看起来像这样:
<asp:sqldatasource id="SqlDataSourceGames" runat="server" connectionstring="<%$ ConnectionStrings:gamesconstring %>"
selectcommand="SELECT uname, uimg
FROM games
INNER JOIN categories_games
ON games.uid = categories_games.uid
INNER JOIN consoles_games
ON games.uid = consoles_games.uid
WHERE consoleid = 2
AND categoryid = @categoryid">
<SelectParameters>
<asp:QueryStringParameter Name="categoryid" DbType ="String" Direction="Input" QueryStringField="categoryid" DefaultValue="" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:sqldatasource>
这很好,我可以通过输入localhost/PS4.aspx?categoryid=1来指定类型。但是,如果未指定categoryid,我希望显示所有类型。换句话说,当我进入localhost/PS4.aspx.
我尝试使用CancelSelectOnNullParameter="false"
,但没有任何效果。
使用
...
selectcommand="SELECT uname, uimg
FROM games
INNER JOIN categories_games
ON games.uid = categories_games.uid
INNER JOIN consoles_games
ON games.uid = consoles_games.uid
WHERE consoleid = 2
AND (categoryid = @categoryid OR @categoryid IS NULL)"
CancelSelectOnNullParameter="false">