表内容为:
字段1 字段2  字段3
*      NULL   NULL
*      NULL   NULL
*      NULL   NULL
NULL    *     NULL
NULL    *     NULL
NULL   NULL    *
NULL   NULL    *预备把字段1与DropDownList1绑定,字段2与DropDownList2绑定,字段3与DropDownList3绑定,DropDownList显示时不显示空字段,用一次搜索完成:
            //要求下拉显示时不显示空字段
            string sql = "select * from 表名";
            SqlDataAdapter sda = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            sda.Fill(ds, 表名);
            this.DropDownList1.DataSource = ds.Tables["表名"];
            this.DropDownList1.DataValueField = "ID";
            this.DropDownList1.DataTextField = "字段1";
            this.DropDownList1.DataBind();
             请问,如何不显示空字段的,最好在后台实现的,或者前台实现(我不太熟悉的,呵呵)也行?前提是,我搜索一次数据库,DropDownList显示对应字段时,不显示空字段的。请给出具体代码,非常感谢!

解决方案 »

  1.   

    第一自己逐个删除
    第二 使用 DataTable.Select  
    第三 DataTable.DefaultView.RowFilter
      

  2.   

    请问,DataTable.Select 具体如何实现呢?是绑定前就操作么?麻烦你在下面代码基础上改下的,谢谢了!  string sql = "select * from 表名";
      SqlDataAdapter sda = new SqlDataAdapter(sql, con);
      DataSet ds = new DataSet();
      sda.Fill(ds, 表名);
      this.DropDownList1.DataSource = ds.Tables["表名"];
      this.DropDownList1.DataValueField = "ID";
      this.DropDownList1.DataTextField = "字段1";
      this.DropDownList1.DataBind();
      

  3.   

    当你填充DataTable后就可以使用了,在已有数据集中再一次筛选,看帮助吧
      

  4.   

     这些代码不变么?
      string sql = "select * from 表名";
      SqlDataAdapter sda = new SqlDataAdapter(sql, con);
      DataSet ds = new DataSet();sda.Fill(ds, 表名); 之后用DataTable 么?但是ds没有这个东东啊?能否给出具体的呢,比较着急,是新手的,复制粘贴比较多,请帮忙了,谢谢!
      

  5.   

    没搞定啊,如何实现把一个表格的各个字段,去除空记录,然后分别绑定到不同的dropdownlist上呢,请哪位给出具体的方法啊,谢谢!
      

  6.   

    表格内容填充之后,然后对每一列单独进行刷选(不能影响到其它列的数据),然后将筛选后的各列与dropdownlist绑定,如何实现呢?看帮助搞不定的