问个关于下拉框的菜鸟问题,大家快来抢分吧,利马结贴

时间:2022-09-30 16:45:03
vs2005中实现2个下拉框联动,是不是已经有了封装好的方法,利用js?如何实现?利马揭帖.

15 个解决方案

#1


C#下实现主从DropDownList互动的方法
作者: 未知
日期: 


相信和我一样,有很多同行都遇到主从dropdownlist互动的问题,比如选择了县,那么让系统自动在dropdownlist2中列出该县下属的乡名列表,而选了乡后,再在dropdownlist3中列出该乡下属的村的列表,那么我以前的解决方法是重新Rill相应dropdownlist所绑定的dataset,这样费事费资源,而且麻烦,其实我们可以用RowFilter来实现,下面是我的具体实现方法:

override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
InitA();//该方法不能放置在Page_Load下 不管是否IsPostBack;
}

//初始化dorpdownlist

DataSet Myds;
//CConection 为我的自定义类;实现与数据库的连接,其中有一属性为cnn,为OleDbConnection.
CConection Mycnn;

public void InitA()//可以为private void InitA()
{
Mycnn=new CConection();
string strSql;
strSql="select 编号,名称 from sys_county order by 编号";
OleDbDataAdapter MyoleAp=new OleDbDataAdapter(strSql,Mycnn.Cnn) ;
Myds=new DataSet() ;
MyoleAp.Fill(Myds,"sys_county");
this.DropDownList1.DataSource=Myds.Tables["sys_county"];
this.DropDownList1.DataValueField="编号";
this.DropDownList1.DataTextField="名称";
this.DropDownList1.DataBind();
strSql="select 编号,名称,所属县 from sys_town order by 编号";
MyoleAp.SelectCommand.CommandText=strSql;
MyoleAp.Fill(Myds,"sys_town");
this.DropDownList2.DataSource=Myds.Tables["sys_town"];//必须指定Table 比如myds.Tables[0];
this.DropDownList2.DataValueField="编号";
this.DropDownList2.DataTextField="名称";//这里也可以初始化绑定全部 this.DropDownList2.DataBind();
MyoleAp.Dispose();

}

//DropDownList1的changed改变dorpdownlist2的显示值,

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Myds.Tables["sys_town"].DefaultView.RowFilter="所属县='" + this.DropDownList1.SelectedValue +"'";
this.DropDownList2.DataBind();
}
[注意:]以上代码在C#的webform下实现,dropdownlist1的autopostback必须为true.

#2


http://www.knowsky.com/302432.html

http://www.knowsky.com/4707.html(可下载代码)


给出了思路,要代码;
给出了代码,要C#的;
给出了C#码,还说不明白......

唉,好人难做啊......

#3


必须要js么?

#4


高手就是高手,这么又文采

#5


若用cs来写可以利用SelectedIndexChanged事件,很容易

#6


deadshot123(随风缘) 就可以解决问题了

#7


顶一下..

#8


http://singlepine.cnblogs.com/articles/265678.html

#9


谢谢各位,可能是我说得不清楚

我想问的是

vs2005

中关于2个下拉框联动

是不是有了新封装好的方法,好像和js有点关系

怎么使用?再谢

#10


第一个选好,第二个根据第一个的值在查询,然后绑定。如果访问大这样可能有点慢
用js可以先把第二个所有数据的读出来,根据第一个的value用js来控制第二个的显示。

#11


嗯,谢谢,这个是vs2005中的新方法吗?

#12


up

#13


丢,2005这么快就用上了啊

#14


帮顶一下

#15


还是木人帮忙解答小弟心中困惑啊。晕。

#1


C#下实现主从DropDownList互动的方法
作者: 未知
日期: 


相信和我一样,有很多同行都遇到主从dropdownlist互动的问题,比如选择了县,那么让系统自动在dropdownlist2中列出该县下属的乡名列表,而选了乡后,再在dropdownlist3中列出该乡下属的村的列表,那么我以前的解决方法是重新Rill相应dropdownlist所绑定的dataset,这样费事费资源,而且麻烦,其实我们可以用RowFilter来实现,下面是我的具体实现方法:

override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
InitA();//该方法不能放置在Page_Load下 不管是否IsPostBack;
}

//初始化dorpdownlist

DataSet Myds;
//CConection 为我的自定义类;实现与数据库的连接,其中有一属性为cnn,为OleDbConnection.
CConection Mycnn;

public void InitA()//可以为private void InitA()
{
Mycnn=new CConection();
string strSql;
strSql="select 编号,名称 from sys_county order by 编号";
OleDbDataAdapter MyoleAp=new OleDbDataAdapter(strSql,Mycnn.Cnn) ;
Myds=new DataSet() ;
MyoleAp.Fill(Myds,"sys_county");
this.DropDownList1.DataSource=Myds.Tables["sys_county"];
this.DropDownList1.DataValueField="编号";
this.DropDownList1.DataTextField="名称";
this.DropDownList1.DataBind();
strSql="select 编号,名称,所属县 from sys_town order by 编号";
MyoleAp.SelectCommand.CommandText=strSql;
MyoleAp.Fill(Myds,"sys_town");
this.DropDownList2.DataSource=Myds.Tables["sys_town"];//必须指定Table 比如myds.Tables[0];
this.DropDownList2.DataValueField="编号";
this.DropDownList2.DataTextField="名称";//这里也可以初始化绑定全部 this.DropDownList2.DataBind();
MyoleAp.Dispose();

}

//DropDownList1的changed改变dorpdownlist2的显示值,

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Myds.Tables["sys_town"].DefaultView.RowFilter="所属县='" + this.DropDownList1.SelectedValue +"'";
this.DropDownList2.DataBind();
}
[注意:]以上代码在C#的webform下实现,dropdownlist1的autopostback必须为true.

#2


http://www.knowsky.com/302432.html

http://www.knowsky.com/4707.html(可下载代码)


给出了思路,要代码;
给出了代码,要C#的;
给出了C#码,还说不明白......

唉,好人难做啊......

#3


必须要js么?

#4


高手就是高手,这么又文采

#5


若用cs来写可以利用SelectedIndexChanged事件,很容易

#6


deadshot123(随风缘) 就可以解决问题了

#7


顶一下..

#8


http://singlepine.cnblogs.com/articles/265678.html

#9


谢谢各位,可能是我说得不清楚

我想问的是

vs2005

中关于2个下拉框联动

是不是有了新封装好的方法,好像和js有点关系

怎么使用?再谢

#10


第一个选好,第二个根据第一个的值在查询,然后绑定。如果访问大这样可能有点慢
用js可以先把第二个所有数据的读出来,根据第一个的value用js来控制第二个的显示。

#11


嗯,谢谢,这个是vs2005中的新方法吗?

#12


up

#13


丢,2005这么快就用上了啊

#14


帮顶一下

#15


还是木人帮忙解答小弟心中困惑啊。晕。