欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Asp.net treeview實(shí)現無(wú)限級樹(shù)實(shí)現代碼
最近研究了一下treeview,發(fā)現有兩種實(shí)現無(wú)限級樹(shù)的方法,文字不想多寫(xiě),直入主題。

先看看效果圖:

先看看數據庫表的設計,數據表主要包括ID,Name,ParentID這三項,其中ID是主鍵,ParentID對應節點(diǎn)的父節點(diǎn):


方法一:用遞歸遍歷數據,并將節點(diǎn)逐個(gè)添加到treeview中去。
1.先進(jìn)行數據庫連接和數據的讀取,并將根節點(diǎn)先添加進(jìn)treeview中,并利用遞歸getTreeView()實(shí)現數據的遍歷和添加:
代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TreeNode nodeCategory ;
connection conn = new connection();
List<Category> category = conn.getCategory();
Stack<Category> storeCategory = new Stack<Category>();
storeCategory.Push(category[0]);
nodeCategory = new TreeNode(category[0].Name.Trim(), category[0].Id.Trim());
TreeView1.Nodes.Add(nodeCategory);
getTreeView(storeCategory, category, nodeCategory);
}
}

2.數據遍歷的遞歸函數,比較簡(jiǎn)單就不多說(shuō)了。
代碼如下:
public void getTreeView(Stack<Category> categoryStack,List<Category> categoryList,TreeNode e)
{
Category tmp;
if(categoryStack.Count>0)
{
tmp=categoryStack.Pop();
for(int i=0;i<categoryList.Count;i++)
if(categoryList[i].ParentId.Trim()==tmp.Id.Trim())
{
categoryStack.Push(categoryList[i]);
TreeNode childNote = new TreeNode(categoryList[i].Name.Trim(), categoryList[i].Id.Trim());
e.ChildNodes.Add(childNote);
getTreeView(categoryStack, categoryList, childNote);
}
}
}

方法二:用TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)事件響應來(lái)逐個(gè)讀取子節點(diǎn)。
1.第一步基本和上一方法的第一步一致,只是要將節點(diǎn)的設置為不展開(kāi)。
代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TreeNode nodeCategory ;
connection conn = new connection();
List<Category> category = conn.getCategory();
nodeCategory = new TreeNode(category[0].Name.Trim(), category[0].Id.Trim());
nodeCategory.PopulateOnDemand = true;
nodeCategory.Collapse();
nodeCategory.NavigateUrl = "http://blog.csdn.net/longlongago2000";
nodeCategory.Target = "_blank";
TreeView1.Nodes.Add(nodeCategory);
}
}

2.再改寫(xiě)TreeView1_TreeNodePopulate(),根據鼠標的點(diǎn)擊得到該節點(diǎn)的ID,然后根據該ID進(jìn)行數據的讀取,將其下的子節點(diǎn)讀出。
代碼如下:
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
int categoryID = Int32.Parse(e.Node.Value);
connection conn = new connection();
List<Category> category = conn.getCategory();
foreach (Category tmp in category)
{
if (categoryID.ToString() == tmp.ParentId.Trim())
{
TreeNode childNote = new TreeNode(tmp.Name.Trim(), tmp.Id.Trim());
foreach (Category cate in category)
{
if (tmp.Id.Trim() == cate.ParentId.Trim())
{
childNote.PopulateOnDemand = true;
childNote.Collapse();
break;
}
else
childNote.Expand();
}
childNote.NavigateUrl ="http://blog.csdn.net/longlongago2000" ;
childNote.Target = "_blank";
e.Node.ChildNodes.Add(childNote);
}
}

以上兩種方法都可以實(shí)現無(wú)限級分類(lèi),不過(guò)第一種方法顯然更好一些,第二種方法不可以實(shí)現全部展開(kāi)功能,而第一種可以。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C# TreeView編輯
C# 多線(xiàn)程操作TreeView
V9.5TreeView 控件
c#中Treeview的使用_到城里啃青
ASP.NET中TreeView控件使用小結
使用 TreeView IE Web 控件
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久