一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

asp.net DropDownList 三級聯動下拉菜單實現代碼

復制代碼 代碼如下:
if (!IsPostBack)
{
//一級分類列表
this.DropDownList1.DataSource = dsbb.SelectSubjct1();
this.DropDownList1.DataTextField = "cName";
this.DropDownList1.DataValueField = "Ccode";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0,new ListItem("請選擇一級分類","0"));
this.DropDownList8.Items.Insert(0, new ListItem("請選擇二級分類", "0"));
this.DropDownList9.Items.Insert(0,new ListItem ("請選擇三級分類","0"));
//二級分類列表

}
/// <summary>
/// 綁定二級分類
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
libs.Database.Dbbase dbb = new libs.Database.Dbbase();
if (Convert.ToInt32(this.DropDownList1.SelectedValue) == 0) //清除列表內容
{
this.DropDownList8.Items.Clear();
this.DropDownList8.Items.Insert(0, new ListItem("請選擇二級分類", "0"));
this.DropDownList9.Items.Clear();
this.DropDownList9.Items.Insert(0, new ListItem("請選擇三級分類", "0"));
}
else //二級分類列表
{
this.DropDownList8.DataSource = dbb.Selectsubjct2(this.DropDownList1.SelectedValue.Substring(0,2));
this.DropDownList8.DataTextField = "cName";
this.DropDownList8.DataValueField = "Ccode";
this.DropDownList8.DataBind();
this.DropDownList8.Items.Insert(0,new ListItem ("請選擇二級分類","0"));
this.DropDownList9.Items.Clear();//清除第三分類
this.DropDownList9.Items.Insert(0, new ListItem("請選擇三級分類", "0"));
}
}
/// <summary>
/// 綁定三級分類
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
{
libs.Database.Dbbase dbase = new libs.Database.Dbbase();
this.DropDownList9.DataSource = dbase.selectsubject3(this.DropDownList8.SelectedValue.Substring(0,4));
this.DropDownList9.DataTextField = "cName";
this.DropDownList9.DataValueField = "Ccode";
this.DropDownList9.DataBind();
this.DropDownList9.Items.Insert(0,new ListItem("請選擇三級分類","0"));
}


Dbbase.cs頁:
復制代碼 代碼如下:
/// <summary>
/// 查詢一級欄目
/// </summary>
/// <returns></returns>
public DataSet SelectSubjct1()
{
string con = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = new SqlConnection(con);
string sqlstr = "SELECT kndid, Ccode, cName, cLevel FROM kind WHERE cLevel = 1";
DataSet dst = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(sqlstr,conn);
try
{
sda.Fill(dst);
return dst;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}
/// <summary>
/// 查詢二級欄目內容
/// </summary>
/// <param name="ccode"></param>
/// <returns></returns>
public DataSet Selectsubjct2(string ccode)
{
string conn1 = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = new SqlConnection(conn1);
string sqqq = "select kndid,Ccode,cName,cLevel from kind where cLevel = 2 and Ccode like '" + ccode + "%'";
DataSet dss = new DataSet();
SqlDataAdapter sdd = new SqlDataAdapter(sqqq,conn);
try
{
sdd.Fill(dss);
return dss;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}
/// <summary>
/// 查詢三級欄目內容
/// </summary>
/// <param name="cde"></param>
/// <returns></returns>
public DataSet selectsubject3(string cde)
{
string conn2 = System.Configuration.ConfigurationSettings.AppSettings["sqlconn"];
SqlConnection conn = new SqlConnection(conn2);
string sqq = "select kndid,Ccode,cName,cLevel from kind where cLevel = 3 and Ccode like '" + cde + "%'";
DataSet dst = new DataSet();
SqlDataAdapter sdaa = new SqlDataAdapter(sqq,conn);
try
{
sdaa.Fill(dst);
return dst;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
conn.Close();
}
}

注意:DropDownList1_SelectedIndexChanged 事件,AutoPostBack="True"

AspNet技術asp.net DropDownList 三級聯動下拉菜單實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 91精品视频在线观看免费 | 视色4se视频在线观看 | 亚洲综合色婷婷在线观看 | 久久伊人中文字幕有码 | 中文字幕一区视频一线 | 国产欧美一区二区三区在线 | 激性欧美激情在线播放16页 | 免费国产高清视频 | 男女免费爽爽爽在线视频 | 亚洲第一页综合 | 久久97久久97精品免视看清纯 | 免费一区二区三区四区 | 四虎影视永久免费观看网址 | 在线播放一区二区精品产 | 亚洲国产成人精品女人久久久 | 亚洲精品乱码国产精品乱码 | 久久综合久久网 | 午夜国产高清精品一区免费 | 免费国产成高清人在线视频 | 国产高清精品一区 | 欧美人与z0z0xxxx | 国产原创精品视频 | 精品久久久久久中文字幕 | 成人第一页 | 国产原创中文字幕 | 成人激情免费视频 | 91正在播放 | 国产成人精品一区二三区在线观看 | 成人午夜视频在线 | 久久久久久尹人网香蕉 | 亚洲一区二区三区久久精品 | 美女被性调教视频在线观看 | 五月激情视频 | 激情婷婷在线 | 国产在线观看精品一区二区三区91 | 国产福利亚洲 | 欧美xxxx做受欧美人妖 | 久久综合五月开心婷婷深深爱 | 亚洲国产精品日韩高清秒播 | 亚洲综合在线成人一区 | 天天精品视频在线观看资源 |