Skip to content

Need to update my filtering tools

Mike Simo

Asked Aug 2, 2014, 1:24 AM EDT2 answers
Share
LinkedInX
In my application i have ask my friend to help me with coding the filtering tools but we got stock in some parts, so i need your kind support guys to help me with updating my code below such as "var query = query + " where " + conditions;" also "string conditions = "";" we dont have that big experience in c# so for that i refer to you guys if you need more explanation the below youtube link will give more info please check it
https://www.youtube.com/watch?v=nh5fbBuUeOE



Div
C#
 protected void Sortcarbtn_Click(object sender, EventArgs e)
        {


            if (Session["location"] != null)
            {


                using (SqlConnection CarsortCon = new SqlConnection(cs))
                {


                    string maker = (barndcardrlst.SelectedIndex > 0) ? barndcardrlst.SelectedValue : null;
                    string yearfrom = (CarYearfrmDrDw.SelectedIndex > 0) ? CarYearfrmDrDw.SelectedValue : null;
                    string yearto = (CarYeartoDrDw.SelectedIndex > 0) ? CarYeartoDrDw.SelectedValue : null;
                    string gearddl = (GearDrDw.SelectedIndex > 0) ? GearDrDw.SelectedValue : null;
                    string CarCond = (CarCondDrDw.SelectedIndex > 0) ? CarCondDrDw.SelectedValue : null;
                    string prisfrom = (CarPriceFrmDrDw.SelectedIndex > 0) ? CarPriceFrmDrDw.SelectedValue : null;
                    string pristo = (CarPriceToDrDw.SelectedIndex > 0) ? CarPriceToDrDw.SelectedValue : null;
                    string Contrddl = (countrdrdolst.SelectedIndex > 0) ? countrdrdolst.SelectedValue : null;
                    string statddl = (statedrdolst.SelectedIndex > 0) ? statedrdolst.SelectedValue : null;
                    string cityddl = (citiesdrdolst.SelectedIndex > 0) ? citiesdrdolst.SelectedValue : null;




                    string query = (@"select * from ads where Category = @Category
                        AND Country = @Country AND Maker=@brand AND Gear=@G AND Condition=@COND AND Year >@startYear and Year <@endYear");


                    var location = Convert.ToString(Session["location"]);
                    var cat = Convert.ToString(Request.QueryString["cat"]);




                    string conditions = "";




                    if (maker != null) conditions += " maker like '%" + maker + "%' ";


                    if (yearfrom != null) conditions += " and year > " + yearfrom;


                    if (yearto != null) conditions += " and year < " + yearto;


                    if (gearddl != null) conditions += " and gear = '%" + gearddl + "%' ";


                    if (CarCond != null) conditions += " Condition = '%" + CarCond + "%' ";


                    if (prisfrom != null) conditions += " and price > " + prisfrom;


                    if (pristo != null) conditions += " and price < " + pristo;


                    if (Contrddl != null) conditions += " Country = '%" + Contrddl + "%' ";


                    if (statddl != null) conditions += " State = '%" + statddl + "%' ";


                    if (cityddl != null) conditions += " City = '%" + cityddl + "%' ";






                    var query = query + " where " + conditions;




                    CarsortQ.Fill(CarsortDataSet);


                    cateshowlistview.DataSource = CarsortDataSet.Tables[0];
                    cateshowlistview.DataBind();


                }


            }
        }

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    what's the issue that you're facing in the code?

    any error or not relevant result.
    0
  • 0
    hi @Sumit Jolly 

    i am trying since long time to code the filtering of my listview and i dont know how i am looking for someone who can help me with coding it, if you watch my youtube link it may gives you an overview of what i am looking for i wish if you can help me by update my coding to be work
    0