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

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

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

開(kāi)通VIP
asp.net為T(mén)reeview動(dòng)態(tài)增加節點(diǎn)實(shí)例

asp.net為T(mén)reeview動(dòng)態(tài)增加節點(diǎn)實(shí)例

  • 標簽:Treeview 樹(shù)形菜單  更新時(shí)間:2014-01-07
  • 在asp.net中使用TreeView,如果是靜態(tài)的增加節點(diǎn)數據,這個(gè)很好辦,但一般情況下,TreeView是要動(dòng)態(tài)顯示菜單項的,大部分都是從XML或Access、SqlServer數據庫中加載內容,要從數據庫中讀出內容動(dòng)態(tài)增加結點(diǎn),其實(shí)也不難,比如以SQL2000的PUBS數據庫為例子,我們以樹(shù)型列表方式取出“作者”做為根結點(diǎn),再取出對應作者的作品作為子節點(diǎn),來(lái)實(shí)現動(dòng)態(tài)展開(kāi)并加載數據的TreeView,我們可以這樣做:

    <%@ Page Language="C#"%><%@ Import Namespace="System.Data"%><%@ Import Namespace="System.Data.SqlClient"%><%@ Import Namespace="System.Configuration"%><!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Dynamic Population of the TreeView Control</title><script runat=server>void Node_Populate(object sender,System.Web.UI.WebControls.TreeNodeEventArgs e){if(e.Node.ChildNodes.Count == 0){switch( e.Node.Depth ){case 0:FillAuthors(e.Node);break;case 1:FillTitlesForAuthors(e.Node);break;}}}void FillAuthors(TreeNode node){string connString = System.Configuration.ConfigurationSettings.ConnectionStrings["NorthwindConnnection"].ConnectionString;SqlConnection connection = new SqlConnection(connString);SqlCommand command = new SqlCommand("Select * Fromauthors",connection);SqlDataAdapter adapter = new SqlDataAdapter(command);DataSet authors = new DataSet();adapter.Fill(authors);if (authors.Tables.Count > 0){foreach (DataRow row in authors.Tables[0].Rows){TreeNode newNode = newTreeNode(row["au_fname"].ToString() + " " +row["au_lname"].ToString(),row["au_id"].ToString());newNode.PopulateOnDemand = true;newNode.SelectAction = TreeNodeSelectAction.Expand;node.ChildNodes.Add(newNode);}}}void FillTitlesForAuthors(TreeNode node){string authorID = node.Value;string connString = System.Configuration.ConfigurationSettings.ConnectionStrings["NorthwindConnnection"].ConnectionString;SqlConnection connection = new SqlConnection(connString);SqlCommand command = new SqlCommand("Select T.title,T.title_id From titles T" +" Inner Join titleauthor TA on
    T.title_id = TA.title_id " +
    " Where TA.au_id = '" + authorID + "'", connection);
    SqlDataAdapter adapter = new SqlDataAdapter(command);
    DataSet titlesForAuthors = new DataSet();
    adapter.Fill(titlesForAuthors);
    if (titlesForAuthors.Tables.Count > 0)
    {
    foreach (DataRow row in titlesForAuthors.Tables[0].Rows)
    {
    TreeNode newNode = new TreeNode(
    row["title"].ToString(), row["title_id"].ToString());
    newNode.PopulateOnDemand = false;
    newNode.SelectAction = TreeNodeSelectAction.None;
    node.ChildNodes.Add(newNode);
    }
    }
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TreeViewRunat="Server" ExpandImageUrl="Images/closed.gif"
    CollapseImageUrl="Images/open.gif"
    OnTreeNodePopulate="Node_Populate" ID="tvwauthors">
    <Nodes>
    <asp:TreeNodeText="Authors" PopulateOnDemand=true
    Value="0"/>
    </Nodes>
    </asp:TreeView>
    </div>
    </form>
    </body>
    </html>

    其中,要注意ontreenodepopulate事件,是在展開(kāi)樹(shù)結點(diǎn)時(shí)發(fā)生的,這里自定義了node_populate來(lái)檢查當前結點(diǎn)的深度,如果是0,就是根結點(diǎn),于是就調用FillAuthors過(guò)程,取出所有的作者,如果深度是1,則是子節點(diǎn),調用FillTitlesForAuthors過(guò)程讀取作品信息。其中,要注意動(dòng)態(tài)建立樹(shù)結點(diǎn)的過(guò)程,如下代碼:

    TreeNode newNode = new TreeNode(row["au_fname"].ToString() + " " +
    row["au_lname"].ToString(),
    row["au_id"].ToString());
    newNode.PopulateOnDemand = true;
    newNode.SelectAction = TreeNodeSelectAction.Expand;
    node.ChildNodes.Add(newNode);

    從popluateondemand的屬性來(lái)看,該節點(diǎn)可以動(dòng)態(tài)擴展。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C#生成無(wú)限級別菜單 treeview綁定數據庫 實(shí)踐成果
Asp.Net中使用TreeView連接數據庫動(dòng)態(tài)加載節點(diǎn)問(wèn)題
TreeView綁定產(chǎn)品信息
數據庫驅動(dòng)的asp.net treeview
TreeView動(dòng)態(tài)構造多級樹(shù)并實(shí)現拖動(dòng)(收藏)
ASP.NET TreeView樹(shù)型菜單操作實(shí)例(代碼調試通過(guò)) - mdl821120的...
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

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