mardi 20 octobre 2015

Random ListView begavior asp.net

I took a course at asp.net and now a year after I want to make a project. I was thinking about an ecommerce website.

Im displaying my products usingListView` from the DB (MSSQL). I want to make it Random - so whenever I refresh the page I see the products in a different order.

How should I approach ?

Thanks guys :)

         <asp:ListView ID="lvProducts" runat="server">
        <ItemTemplate>
            <table>
                <tr><td><img src="<%#Eval("ImagePath") %>" style="width: 150px; height: 150px;" /></td></tr>
                <tr><td><h1><%#Eval("Brand") %></h1></td></tr>
                <tr><td><h2><%#Eval("Model") %></td></tr>
                <tr><td><h3><%#Eval("Price") %></td></tr>
            </table>
        </ItemTemplate>
    </asp:ListView>

code behind:

     protected void Page_Load(object sender, EventArgs e)
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString);
    SqlDataAdapter ProductData = new SqlDataAdapter("SELECT * FROM TEST", conn);
    DataTable dtProduct = new DataTable();
    ProductData.Fill(dtProduct);

    lvProducts.DataSource = dtProduct;
    lvProducts.DataBind();
}

Aucun commentaire:

Enregistrer un commentaire