一区二区久久-一区二区三区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在线亚洲 | 嫩草影院一区 | 欧美三级网站 | 久久国产乱子伦精品免费看 | 中文字幕精品在线观看 | 色播在线观看 | 999久久66久6只有精品 | 久久无码精品一区二区三区 | 美女很黄很黄是免费的 | 国产午夜亚洲精品不卡福利 | 91精品一区二区三区久久久久 | 国产福利在线观看 极品美女 | 欧美视频在线观看网站 | 久久国产乱子伦精品免费看 | 成人国产欧美精品一区二区 | 亚洲激情中文字幕 | 国产精品久久久亚洲 | 99re6这里只有精品 | 国产精品拍自在线观看 | 男人女人做刺激视频免费 | 美女网站在线 | 国产91精品久久久久久 | 精品一区二区三区无卡乱码 | 伊人久久综合网亚洲 | 中国a毛片 | 日韩一区二区久久久久久 | 色哟哟视频在线观看网站 | 成人小视频在线 | 亚洲爱爱爱 | 精品精品 | 日本三级成人中文字幕乱码 | 四虎影视久久久 | 亚洲黄色在线观看视频 | 91精彩视频在线观看 | 五月天天| 日韩色爱| 国产一区二区三区福利 | 青青草国产精品人人爱99 | 2021国产精品自在拍在线播放 | 国产精品久久久久久久成人午夜 | 久久99精品久久久久久青青91 |