根据许多下拉列表对datalist进行排序 [英] Sort datalist depending on many dropdownlists

查看:155
本文介绍了根据许多下拉列表对datalist进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




以下代码与我合作对汽车品牌和Gear进行排序,还有两个下拉列表(DropDownList3,DropDownList6),允许用户选择汽车年由数据库表中名为Year的列创建,例如:从2008年到2012年。所以我如何更新下面的代码以从这两个下拉列表中获取所选值并给出这两个选定值之间的记录



i上传了一个屏幕记录,我希望能解释更多关于我要找的内容:



https://www.youtube.com/watch?v=nh5fbBuUeOE&feature=youtu.be



Hi
The below code its working fine with me to sort the car brand and the Gear, but also i have two dropdownlists (DropDownList3 , DropDownList6) which is allow user to choose the car year made from a column in database table called Year, for example: from 2008 to 2012. so how i can update my code below to get the selected value from this two dropdownlist and gives the records between this two selected values

i have upload a screen record i wish that will explain more about what i am looking for:

https://www.youtube.com/watch?v=nh5fbBuUeOE&feature=youtu.be

protected void Sortcarbtn_Click(object sender, EventArgs e)
        {

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

                using (SqlConnection CarsortCon = new SqlConnection(cs))
                {
                    CarsortCon.Open();
                    using (var CarsortQ = new SqlDataAdapter(@"SELECT DISTINCT AdsID, Section, Category, Year, Country, State, City, AdsTit, Maker,Gear, 
                        SUBSTRING(AdsDesc,1,155) as AdsDesc, AdsPrice, Img1 FROM ads WHERE Category = @Category AND Country = @Country AND Maker=@brand AND Gear=@G", cs))
                    {
                        var location = Convert.ToString(Session["location"]);
                        var cat = Convert.ToString(Request.QueryString["cat"]);

                        var CarsortDS = new DataSet();
                        CarsortQ.SelectCommand.Parameters.AddWithValue("@Category", cat);
                        CarsortQ.SelectCommand.Parameters.AddWithValue("@Country", location);
                        CarsortQ.SelectCommand.Parameters.AddWithValue("@brand", catcardrlst.SelectedValue);
                        CarsortQ.SelectCommand.Parameters.AddWithValue("@G", DropDownList1.SelectedValue);


                        CarsortQ.Fill(CarsortDS);

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


                    }
                }
            }

推荐答案

您可以排序在DataTable中使用DataView通过简单传递columnName和ASC或DESC顺序.. :)



You can sort in DataTable using DataView by simple passing columnName and ASC or DESC order.. :)

 DataView dv = dtPreSort.DefaultView;

     string SortField = "ColumnName"; //Pass it dynamically..
     string SortExpression = "ASC OR DESC";

 dv.Sort = SortField+" "+SortExpression;
DataTable dtGetShipments=new  DataTable(); 
 dtGetShipments = dv.ToTable();


这篇关于根据许多下拉列表对datalist进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆