I am using Visual Studio and C#, and I have a DataList that displays games from a database I have. I'm using QueryString to determines which genre (category) I want to display.
The DataList is populated with the game title and image, and my SqlDataSource looks like this:
<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. However, I want to display ALL genres if the categoryid is not specified. In other words, when I go to localhost/PS4.aspx.
I tried using CancelSelectOnNullParameter="false"
, that did nothing.
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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.