主頁 > 知識(shí)庫 > asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹

asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹

熱門標(biāo)簽:臨沂智能電話機(jī)器人加盟 聯(lián)通官網(wǎng)400電話辦理 蘇州如何辦理400電話 網(wǎng)絡(luò)電話外呼系統(tǒng)上海 西寧呼叫中心外呼系統(tǒng)線路商 外呼電話機(jī)器人成本 400電話辦理怎么樣 地圖標(biāo)注軟件免費(fèi)下載 百應(yīng)電話機(jī)器人外呼系統(tǒng)

本文實(shí)例講述了asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹。分享給大家供大家參考,具體如下:

#region DropDownList無限遞歸顯示層次關(guān)系
/// summary>
/// 創(chuàng)建無限分級(jí)下拉列表框
/// /summary>
/// param name="ddlst">下拉控件/param>
/// param name="dt">源DataTable/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
public static void CreateLevelDropDown(DropDownList ddlst, DataTable dt, string text, string value, string parentid)
{
  ArrayList allItems = new ArrayList();
  DataRow[] rows = dt.Select(parentid + "=0");
  foreach (DataRow row in rows)
    CreateLevelDropDownAssistant(dt, ref  allItems, row, string.Empty, text, value, parentid);
  ListItem[] items = new ListItem[allItems.Count];
  allItems.CopyTo(items);
  ddlst.Items.AddRange(items);
}
/// summary>
/// 遞歸綁定子節(jié)點(diǎn)
/// /summary>
/// param name="dt">源DataTable/param>
/// param name="items">數(shù)組/param>
/// param name="parentRow">當(dāng)前節(jié)點(diǎn)/param>
/// param name="curHeader">前綴/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
private static void CreateLevelDropDownAssistant(DataTable dt, ref  ArrayList items, DataRow parentRow, string curHeader, string text, string value, string parentid)
{
  ListItem newItem = new ListItem(curHeader + Until.CutString(parentRow[text].ToString(), 18, true), parentRow[value].ToString());
  items.Add(newItem);
  DataRow[] rows = dt.Select(parentid + "=" + newItem.Value);
  for (int i = 0; i  rows.Length - 1; i++)
    CreateLevelDropDownAssistant(dt, ref  items, rows[i], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┣", text, value, parentid);
  if (rows.Length > 0)
    CreateLevelDropDownAssistant(dt, ref  items, rows[rows.Length - 1], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┗", text, value, parentid);
}
#endregion
#region TreeView 無限遞歸顯示層次關(guān)系目錄樹
/// summary>
/// 創(chuàng)建無限分級(jí)目錄樹TreeView
/// /summary>
/// param name="treeview">TreeView空間/param>
/// param name="dt">數(shù)據(jù)源DataTable/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
public static void CreateLevelTreeView(TreeView treeview, DataTable dt, string text, string value, string parentid)
{
  DataView dv = dt.DefaultView;
  dv.RowFilter = parentid + "=0";
  foreach (DataRowView drv in dv)
  {
    TreeNode node = new TreeNode();
    node.Text = drv[text].ToString();
    node.Value = drv[value].ToString();
    node.Expanded = false;
    treeview.Nodes.Add(node);
    CreatTreeViewChildNode(dv, node, text, value, parentid);
  }
}
/// summary>
/// 遞歸綁定子節(jié)點(diǎn)
/// /summary>
/// param name="dv">源DataView/param>
/// param name="parentNode">當(dāng)前節(jié)點(diǎn)/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
private static void CreatTreeViewChildNode(DataView dv, TreeNode parentNode, string text, string value, string parentid)
{
  dv.RowFilter = parentid + "=" + parentNode.Value;
  foreach (DataRowView row in dv)
  {
    TreeNode replyNode = new TreeNode();
    replyNode.Text = row[text].ToString();
    replyNode.Value = row[value].ToString();
    replyNode.Expanded = false;
    parentNode.ChildNodes.Add(replyNode);
    CreatTreeViewChildNode(dv, replyNode, text, value, parentid);
  }
}
/// summary>
/// 創(chuàng)建無限分級(jí)目錄樹TreeView
/// /summary>
/// param name="treeview">TreeView空間/param>
/// param name="dt">數(shù)據(jù)源DataTable/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="url">url字段/param>
/// param name="parentid">深度字段 例如parentid/param>
public static void CreateLevelTreeView(TreeView treeview, DataTable dt, string text, string value, string url, string parentid)
{
  DataView dv = dt.DefaultView;
  dv.RowFilter = parentid + "=0";
  foreach (DataRowView drv in dv)
  {
    TreeNode node = new TreeNode();
    node.Text = drv[text].ToString();
    node.Value = drv[value].ToString();
    node.NavigateUrl = drv[url].ToString();
    node.Expanded = false;
    treeview.Nodes.Add(node);
    CreatTreeViewChildNode(dv, node, text, value, url, parentid);
  }
}
/// summary>
/// 遞歸綁定子節(jié)點(diǎn)
/// /summary>
/// param name="dv">源DataView/param>
/// param name="parentNode">當(dāng)前節(jié)點(diǎn)/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="url">url字段/param>
/// param name="parentid">深度字段 例如parentid/param>
private static void CreatTreeViewChildNode(DataView dv, TreeNode parentNode, string text, string value, string url, string parentid)
{
  dv.RowFilter = parentid + "=" + parentNode.Value;
  foreach (DataRowView row in dv)
  {
    TreeNode replyNode = new TreeNode();
    replyNode.Text = row[text].ToString();
    replyNode.Value = row[value].ToString();
    replyNode.NavigateUrl = row[url].ToString();
    replyNode.Expanded = false;
    parentNode.ChildNodes.Add(replyNode);
    CreatTreeViewChildNode(dv, replyNode, text, value, url, parentid);
  }
}
#endregion
#region 創(chuàng)建無限分級(jí)ListBox
/// summary>
/// 創(chuàng)建無限分級(jí)ListBox
/// /summary>
/// param name="ddlst">ListBox控件/param>
/// param name="dt">源DataTable/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
public static void CreateLevelListBox(ListBox ddlst, DataTable dt, string text, string value, string parentid)
{
  ArrayList allItems = new ArrayList();
  DataRow[] rows = dt.Select(parentid + "=0");
  foreach (DataRow row in rows)
    CreateLevelListBoxAssistant(dt, ref  allItems, row, string.Empty, text, value, parentid);
  ListItem[] items = new ListItem[allItems.Count];
  allItems.CopyTo(items);
  ddlst.Items.AddRange(items);
}
/// summary>
/// 遞歸綁定子節(jié)點(diǎn)
/// /summary>
/// param name="dt">源DataTable/param>
/// param name="items">數(shù)組/param>
/// param name="parentRow">當(dāng)前節(jié)點(diǎn)/param>
/// param name="curHeader">前綴/param>
/// param name="text">text字段/param>
/// param name="value">value字段/param>
/// param name="parentid">深度字段 例如parentid/param>
private static void CreateLevelListBoxAssistant(DataTable dt, ref  ArrayList items, DataRow parentRow, string curHeader, string text, string value, string parentid)
{
  ListItem newItem = new ListItem(curHeader + Until.CutString(parentRow[text].ToString(), 18, true), parentRow[value].ToString());
  items.Add(newItem);
  DataRow[] rows = dt.Select(parentid + "=" + newItem.Value);
  for (int i = 0; i  rows.Length - 1; i++)
    CreateLevelListBoxAssistant(dt, ref  items, rows[i], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┣", text, value, parentid);
  if (rows.Length > 0)
    CreateLevelListBoxAssistant(dt, ref  items, rows[rows.Length - 1], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┗", text, value, parentid);
}
#endregion

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • Jquery.TreeView結(jié)合ASP.Net和數(shù)據(jù)庫生成菜單導(dǎo)航條
  • ASP.NET生成樹形顯示的GridView實(shí)現(xiàn)思路
  • 常用的在數(shù)據(jù)庫中建立無限級(jí)樹形菜單的asp.net代碼
  • asp.net 獲取指定文件夾下所有子目錄及文件(樹形)
  • asp.net實(shí)現(xiàn)遞歸方法取出菜單并顯示在DropDownList中(分欄形式)
  • ASP.NET遞歸法求階乘解決思路
  • 遞歸輸出ASP.NET頁面所有控件的類型和ID的代碼
  • asp.net TreeView與XML三步生成列表樹
  • Asp.net treeview實(shí)現(xiàn)無限級(jí)樹實(shí)現(xiàn)代碼
  • asp.net TreeView遞歸循環(huán)子節(jié)點(diǎn)生成樹形菜單實(shí)例

標(biāo)簽:中衛(wèi) 慶陽 臨夏 清遠(yuǎn) 聊城 海西 甘肅

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹》,本文關(guān)鍵詞  asp.net,實(shí)現(xiàn),DropDownList,TreeView,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章