表内容为:
字段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 字段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显示对应字段时,不显示空字段的。请给出具体代码,非常感谢!
第二 使用 DataTable.Select
第三 DataTable.DefaultView.RowFilter
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();
string sql = "select * from 表名";
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();sda.Fill(ds, 表名); 之后用DataTable 么?但是ds没有这个东东啊?能否给出具体的呢,比较着急,是新手的,复制粘贴比较多,请帮忙了,谢谢!