private void BindBikes()
    {
        string conn  = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        string query = "SELECT * FROM Bike WHERE Availability = '1'";

        if (Session["category"].ToString() != "0")
        {
            query += " AND Category='" + Session["category"] + "' ";
        }
        //if (Session["searchItem"].ToString() != null)
        //{
        //    query += " AND AdsHeader='"+'%' + Session["searchItem"] + '%'+"' ";
        //    Session["searchItem"] = "";
        //}
        query += " order by AddingDate DESC ";
        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand(query, con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    RepBikes.DataSource = dt;
                    RepBikes.DataBind();
                }
            }
        }
    }
    protected void sortBikes_Click(object sender, EventArgs e)
    {
        string empty       = "0";
        string querySelect = "SELECT * FROM Bike";
        string queryWhere  = " WHERE Availability=1";
        string query       = querySelect + queryWhere;

        if (Session["category"].ToString() != empty)
        {
            query += " AND Category='" + Session["category"] + "' ";
        }
        if (ilBike.SelectedValue != empty)
        {
            query += " AND BikeCity='" + ilBike.SelectedValue + "' ";
        }
        if (ilceBike.SelectedValue != empty)
        {
            query += " AND BikeCounty='" + ilceBike.SelectedValue + "' ";
        }
        if (vites.SelectedValue != empty)
        {
            query += " AND Transmission='" + vites.SelectedValue + "' ";
        }
        if (minPrice.Text != "")
        {
            float minPriceInt = float.Parse(minPrice.Text, System.Globalization.CultureInfo.InvariantCulture);
            query += " AND Price>=" + minPriceInt + " ";
        }
        if (maxPrice.Text != "")
        {
            float maxPriceInt = float.Parse(maxPrice.Text, System.Globalization.CultureInfo.InvariantCulture);
            query += " AND Price<=" + maxPriceInt + " ";
        }
        query += " order by AddingDate DESC ";


        string conn = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand(query, con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    RepBikes.DataSource = dt;
                    RepBikes.DataBind();
                }
            }
        }
    }
Ejemplo n.º 3
0
    private void BindBikes()
    {
        string conn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;

        using (SqlConnection con = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand("select * from Bike WHERE Availability='1'", con))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    RepBikes.DataSource = dt;
                    RepBikes.DataBind();
                }
            }
        }
    }