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"
空调维修
- 温岭冰箱全国统一服务热线-全国统一人工【7X2
- 荆州速热热水器维修(荆州热水器维修)
- 昆山热水器故障码5ER-昆山热水器故障码26
- 温岭洗衣机24小时服务电话—(7X24小时)登记报
- 统帅热水器售后维修服务电话—— (7X24小时)登
- 阳江中央空调统一电话热线-阳江空调官方售后电
- 乌鲁木齐阳春燃气灶厂家服务热线
- 珠海许昌集成灶售后服务电话-全国统一人工【
- 乌鲁木齐中央空调维修服务专线-乌鲁木齐中央空
- 新沂热水器故障电话码维修-新沂热水器常见故障
- 诸城壁挂炉24小时服务热线电话
- 靖江空调24小时服务电话-——售后维修中心电话
- 空调室外滴水管维修(空调室外排水管维修)
- 九江壁挂炉400全国服务电话-(7X24小时)登记报修
- 热水器故障码f.22怎么解决-热水器f0故障解决方法
- 营口热水器售后维修服务电话—— 全国统一人工