0
 private void BindProductsRepeater()
{
    String CS = System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(CS))
    {
        using (SqlCommand cmd = new SqlCommand("procBindAllProducts", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable dt = new DataTable();
                sda.Fill(dt);
                rptrProducts.DataSource = dt;
                rptrProducts.DataBind();
            }
        }
    }
}

I have this method which bind items to my repeater via OnItemBound, works perfectly fine. It display product details, title, price, image, I want to create a function where I can order the items by price via sql command. I'm just at wits end on how to do this.

  • Check out this post on how to sort a DataView http://stackoverflow.com/questions/9107916/sorting-rows-in-a-data-table – Goose Apr 14 '17 at 18:07
  • thanks i'll have a look at it now. –  Apr 14 '17 at 18:12
  • 1
    Why not in the `procBindAllProducts` procedure: `SELECT * FROM table ORDER BY price` – VDWWD Apr 14 '17 at 18:22
  • @VDWWD the thing is I only wish to change the query passed to sqlDataAdapter when a button is pressed, for example when the price - high to low is pressed, then i want the databinded to the repeater to change. –  Apr 14 '17 at 18:28
  • Then the link @Goose posted is a possible solution. The other would be to send the sort column as a parameter to the stored procedure and let sql do the sorting for you. – VDWWD Apr 14 '17 at 18:30

0 Answers0