asp.net DropDownList 三级联动下拉菜单实现代码
家电修理 2023-07-16 19:17www.caominkang.com电器维修
复制代码 代码如下:
if (!IsPostBack)
{
//一级分类列表
this.DropDonList1.DataSource = dsbb.SelectSubjct1();
this.DropDonList1.DataTextField = "cName";
this.DropDonList1.DataValueField = "Ccode";
this.DropDonList1.DataBind();
this.DropDonList1.Items.Insert(0,ne ListItem("请选择一级分类","0"));
this.DropDonList8.Items.Insert(0, ne ListItem("请选择二级分类", "0"));
this.DropDonList9.Items.Insert(0,ne ListItem ("请选择三级分类","0"));
//二级分类列表
}
///
/// 绑定二级分类
///
///
///
protected void DropDonList1_SelectedIndexChanged(object sender, EventArgs e)
{
libs.Database.Dbbase dbb = ne libs.Database.Dbbase();
if (Convert.ToInt32(this.DropDonList1.SelectedValue) == 0) //清除列表内容
{
this.DropDonList8.Items.Clear();
this.DropDonList8.Items.Insert(0, ne ListItem("请选择二级分类", "0"));
this.DropDonList9.Items.Clear();
this.DropDonList9.Items.Insert(0, ne ListItem("请选择三级分类", "0"));
}
else //二级分类列表
{
this.DropDonList8.DataSource = dbb.Selectsubjct2(this.DropDonList1.SelectedValue.Substring(0,2));
this.DropDonList8.DataTextField = "cName";
this.DropDonList8.DataValueField = "Ccode";
this.DropDonList8.DataBind();
this.DropDonList8.Items.Insert(0,ne ListItem ("请选择二级分类","0"));
this.DropDonList9.Items.Clear();//清除第三分类
this.DropDonList9.Items.Insert(0, ne ListItem("请选择三级分类", "0"));
}
}
///
/// 绑定三级分类
///
///
///
protected void DropDonList8_SelectedIndexChanged(object sender, EventArgs e)
{
libs.Database.Dbbase dbase = ne libs.Database.Dbbase();
this.DropDonList9.DataSource = dbase.selectsubject3(this.DropDonList8.SelectedValue.Substring(0,4));
this.DropDonList9.DataTextField = "cName";
this.DropDonList9.DataValueField = "Ccode";
this.DropDonList9.DataBind();
this.DropDonList9.Items.Insert(0,ne ListItem("请选择三级分类","0"));
}
Dbbase.cs页
复制代码 代码如下:
///
/// 查询一级栏目
///
///
public DataSet SelectSubjct1()
{
string con = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = ne SqlConnection(con);
string sqlstr = "SELECT kndid, Ccode, cName, cLevel FROM kind WHERe cLevel = 1";
DataSet dst = ne DataSet();
SqlDataAdapter sda = ne SqlDataAdapter(sqlstr,conn);
try
{
sda.Fill(dst);
return dst;
}
catch (Exception ex)
{
thro ne Exception(ex.Message);
}
finally
{
conn.Close();
}
}
///
/// 查询二级栏目内容
///
///
///
public DataSet Selectsubjct2(string ode)
{
string conn1 = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = ne SqlConnection(conn1);
string sqqq = "select kndid,Ccode,cName,cLevel from kind here cLevel = 2 and Ccode like '" + ode + "%'";
DataSet dss = ne DataSet();
SqlDataAdapter sdd = ne SqlDataAdapter(sqqq,conn);
try
{
sdd.Fill(dss);
return dss;
}
catch (Exception ex)
{
thro ne Exception(ex.Message);
}
finally
{
conn.Close();
}
}
///
/// 查询三级栏目内容
///
///
///
public DataSet selectsubject3(string cde)
{
string conn2 = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = ne SqlConnection(conn2);
string sqq = "select kndid,Ccode,cName,cLevel from kind here cLevel = 3 and Ccode like '" + cde + "%'";
DataSet dst = ne DataSet();
SqlDataAdapter sdaa = ne SqlDataAdapter(sqq,conn);
try
{
sdaa.Fill(dst);
return dst;
}
catch (Exception ex)
{
thro ne Exception(ex.Message);
}
finally
{
conn.Close();
}
}
注意DropDonList1_SelectedIndexChanged 事件,AutoPostBack="True"
空调维修
- 我的世界电脑版运行身份怎么弄出来(我的世界
- 空调抽湿是什么意思,设置抽湿的温度有什么意
- 方太燃气灶有一个打不着火 怎么修复与排查方法
- 夏季免费清洗汽车空调的宣传口号
- 清洗完空调后出现漏水现象
- iphone6能玩什么游戏(iphone6游戏)
- 如何设置电脑密码锁屏(如何设置电脑密码锁屏
- win10删除开机密码提示不符合密码策略要求
- 电脑w7显示不是正版(w7不是正版怎么解决)
- 万家乐z8热水器显示e7解决 怎么修复与排查方法
- 1匹空调多少瓦数(1匹空调多少瓦)
- 安卓手机连接电脑用什么软件好(关于安卓手机
- 电脑网页看视频卡是什么原因(爱拍看视频卡)
- 华帝燃气灶点火器一直响然后熄火怎么办:问题
- 电脑壁纸怎么换(关于电脑壁纸怎么换的介绍)
- 冬天空调的出风口应该朝什么方向(冬天空调风