[英]QueryString - Display all entries when parameter isn't specified
I am using Visual Studio and C#, and I have a DataList that displays games from a database I have. 我正在使用Visual Studio和C#,并且有一个DataList可以显示我拥有的数据库中的游戏。 I'm using QueryString to determines which genre (category) I want to display.
我正在使用QueryString确定我要显示的流派(类别)。
The DataList is populated with the game title and image, and my SqlDataSource looks like this: 用游戏标题和图像填充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>
This works fine, and I can specify the genre by entering something like localhost/PS4.aspx?categoryid=1. 这可以正常工作,我可以通过输入类似localhost / PS4.aspx?categoryid = 1的方式来指定流派。 However, I want to display ALL genres if the categoryid is not specified.
但是,如果未指定categoryid,我想显示所有流派。 In other words, when I go to localhost/PS4.aspx.
换句话说,当我转到localhost / PS4.aspx时。
I tried using CancelSelectOnNullParameter="false"
, that did nothing. 我尝试使用
CancelSelectOnNullParameter="false"
,但没有执行任何操作。
Use 采用
...
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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.