Вопрос

I'm working on a project where I have a game library for console games. I'm using ASP.NET with Visual Studio.

Right now I have a database with a table for games, consoles, categories (genres), categories_games (contains gameid and category id to specify what the games genre is) and consoles_games (same thing but for consoles).

I'm displaying the games (the name and the image) using DataList, like this:

<asp:DataList ID="DataList1" runat="server" BackColor="White"
   BorderColor="White" BorderStyle="None" BorderWidth="0px"
   CellPadding="10" CellSpacing="2" Font-Names="Verdana"
   Font-Size="Small" GridLines="Both" RepeatColumns="5"
   RepeatDirection="Horizontal" Width="850px">
      <FooterStyle BackColor="White" ForeColor="#8C4510" />
      <HeaderStyle BackColor="White" Font-Bold="true" Font-Size="Large"
         ForeColor="White" HorizontalAlign="Center"
         VerticalAlign="Middle" />
            <ItemStyle BackColor="White" ForeColor="Black"
               BorderWidth="0px" />
  <ItemTemplate>
    <asp:Image ID="imgGame" runat="server" Width="128px"
    Height="159px" ImageUrl='<%# Bind("uimg", "{0}") %>' />
    <br />
    <asp:Label ID="lblTitle" runat="server"
    Text='<%# Bind("uname") %>'></asp:Label>
    <br />
    <br />
  </ItemTemplate>
</asp:DataList>

Code behind:

protected void BindData()
{
    DataSet ds = new DataSet();
    con.Open();
    SqlCommand cmd = new SqlCommand(cmdstr, con);
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    adp.Fill(ds);
    DataList1.DataSource = ds.Tables[0];
    DataList1.DataBind();
}

As an example, the SQL statement to get all PS4 games looks like this:

SELECT 
    games.uname, games.uimg 
FROM 
    games, consoles, consoles_games 
WHERE 
    consoles.consoleid = consoles_games.consoleid 
    AND games.uid = consoles_games.uid 
    AND consoles.consoleid = 2 
ORDER BY 
    games.uname

However, I want to use a query string to display the games, so I end up with something like this:

mywebsite.com/PS4.aspx?consoleid=2

If anyone knows how I can do this, and still display the games in the DataList the same way I do now, that would be great. I've been looking around for any good tutorials, but I can't seem to find anything that helps me in my situation.

Это было полезно?

Решение

First when user is navigated to ps4 game view (he clicked somewhere before on link or so) you must create querystring. And then on navigated page where you display list of games for ps 4 you should catch that querystring and searched based on passed id or other.

Take a look at: How to build a query string for a URL in C#?

to see how to build query string for a url.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top