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"
空调维修
- 海信电视维修站 海信电视维修站点
- 格兰仕空调售后电话 格兰仕空调维修售后服务电
- 家电售后服务 家电售后服务流程
- 华扬太阳能维修 华扬太阳能维修收费标准表
- 三菱电机空调维修 三菱电机空调维修费用高吗
- 美的燃气灶维修 美的燃气灶维修收费标准明细
- 科龙空调售后服务 科龙空调售后服务网点
- 华帝热水器维修 华帝热水器维修常见故障
- 康泉热水器维修 康泉热水器维修故障
- 华凌冰箱维修电话 华凌冰箱维修点电话
- 海尔维修站 海尔维修站点地址在哪里
- 北京海信空调维修 北京海信空调售后服务
- 科龙空调维修 科龙空调维修故障
- 皇明太阳能售后 皇明太阳能售后维修点
- 海信冰箱售后服务 海信冰箱售后服务热线电话
- 海尔热水器服务热线