请教一个主从DropDownList的问题,在strsql中加了where条件语句就不能实现主从的功能了。不加where条件语句,就能实现。是不能有条件语句吗。现在我要用where条件语句,来选择主DropDownList的数据。可用了where,主DropDownList出现了“个人部”,但从DropDownList没有数据。数据库中是有记录的。不加where条件语句,从DropDownList都有对应于主DropDownList的记录。该怎么改动呢?
DataSet ds =new DataSet();
public void InitA()
{
this.conn.Open();
string strsql;
strsql="select bm from login where bm like '%个人部%' order by bm";
OdbcDataAdapter adapter1=new OdbcDataAdapter(strsql,conn);
adapter1.Fill(ds,"login");
DropDownList1.DataSource = ds.Tables["login"].DefaultView; DropDownList1.DataTextField ="bm"; DropDownList1.DataValueField ="bm"; DropDownList1.DataBind();
string strsql2; strsql2="select distinct name,bm from login ";
adapter1.SelectCommand.CommandText=strsql2;
adapter1.Fill(ds,"login1");
DropDownList2.DataSource=ds.Tables["login1"].DefaultView;
DropDownList2.DataValueField="name";
DropDownList2.DataTextField="name";
//DropDownList2.DataBind();
adapter1.Dispose(); }
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ds.Tables["login1"].DefaultView.RowFilter="bm='" + DropDownList1.SelectedValue +"'";
DropDownList2.DataBind(); }
DataSet ds =new DataSet();
public void InitA()
{
this.conn.Open();
string strsql;
strsql="select bm from login where bm like '%个人部%' order by bm";
OdbcDataAdapter adapter1=new OdbcDataAdapter(strsql,conn);
adapter1.Fill(ds,"login");
DropDownList1.DataSource = ds.Tables["login"].DefaultView; DropDownList1.DataTextField ="bm"; DropDownList1.DataValueField ="bm"; DropDownList1.DataBind();
string strsql2; strsql2="select distinct name,bm from login ";
adapter1.SelectCommand.CommandText=strsql2;
adapter1.Fill(ds,"login1");
DropDownList2.DataSource=ds.Tables["login1"].DefaultView;
DropDownList2.DataValueField="name";
DropDownList2.DataTextField="name";
//DropDownList2.DataBind();
adapter1.Dispose(); }
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ds.Tables["login1"].DefaultView.RowFilter="bm='" + DropDownList1.SelectedValue +"'";
DropDownList2.DataBind(); }
能不能用存储过程来完成。