[英]QueryString - Display all entries when parameter isn't specified
我正在使用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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.