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(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)