[英]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.