一次性在同一个table绑定多个DropDownlist,并且去掉重复项(即代替distinct),从而提高性能。

 private void BindDropDownList(DropDownList ddl2, DropDownList ddl3, DropDownList ddl4, DropDownList ddl5)
    {
        string conn = cs.GetDsn();
        SqlConnection cn = new SqlConnection(conn);
        string strSqlDDL = "select Country,CustName, Substring(CONVERT(varchar(100), ActInstDate, 101),1,2) ActInstDate,ResellerName from  tbcalicoinfo where surveystatus='Completed'";
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(strSqlDDL, cn);
        cn.Open();
        da.Fill(ds, "tbcalicoinfo");
        DataTable dt = new DataTable();      
        ds.Tables["tbcalicoinfo"].DefaultView.RowFilter = "country is not null";//RowFilter 过滤
        ds.Tables["tbcalicoinfo"].DefaultView.Sort = "country asc";  //Sort 排序
        ddl2.DataSource = ds.Tables["tbcalicoinfo"].DefaultView.ToTable(true, "country");// ToTable去重复
        ddl2.DataTextField = "country";
        ddl2.DataBind();
        ddl2.Items.Insert(0, new ListItem("--All--", "All"));

        ds.Tables["tbcalicoinfo"].DefaultView.RowFilter = "ActInstDate is not null";
        ds.Tables["tbcalicoinfo"].DefaultView.Sort = "ActInstDate asc";
        ddl3.DataSource = ds.Tables["tbcalicoinfo"].DefaultView.ToTable(true, "ActInstDate"); ;
        ddl3.DataTextField = "ActInstDate";
        ddl3.DataBind();
        ddl3.Items.Insert(0, new ListItem("--All--", "All"));

        //DataRow[] dr2 = dt.Select("ResellerName is not null","ResellerName asc");
        ds.Tables["tbcalicoinfo"].DefaultView.RowFilter = "ResellerName is not null";
        ds.Tables["tbcalicoinfo"].DefaultView.Sort = "ResellerName asc";
        ddl4.DataSource = ds.Tables["tbcalicoinfo"].DefaultView.ToTable(true, "ResellerName");
        ddl4.DataTextField = "ResellerName";
        ddl4.DataBind();
        ddl4.Items.Insert(0, new ListItem("--All--", "All"));

        ds.Tables["tbcalicoinfo"].DefaultView.RowFilter = "CustName is not null";
        ds.Tables["tbcalicoinfo"].DefaultView.Sort = "CustName asc";
        ddl5.DataSource = ds.Tables["tbcalicoinfo"].DefaultView.ToTable(true, "CustName");
        ddl5.DataTextField = "CustName";
        ddl5.DataBind();
        ddl5.Items.Insert(0, new ListItem("--All--", "All"));
        cn.Close();

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值