【原】母版页、皮肤、导航 那点事 Master Pages Themes and Navigation Controls FAQ 【续一篇:导航树】
2009-02-24 13:06
381 查看
考试,考试,还是考试!无聊透顶的考试!但是不考又不行的考试!为了那一张薄薄的纸!我又白白浪费的3年宝贵的时间!强烈建议教育改革!最近我快被考试折磨的不行了!多次想过来写一篇,可是一想到考试,整个心情都没有了!不抱怨了,奉献点真东西给观众。
最近我遇到朋友问我,如何动态的在现有的TreeView控件上添加节点的问题,我找到了一些国外的站点,的确有些参考的代码,但是写的都不是太详细。于是我稍微花了点时间,整理了下,就算是和我以前写的那篇呼应一下吧,不过这篇有点单薄,就一篇,但是实用!如果没有读过上一篇的,强烈建议读一读!上一篇的地址是:/article/4871095.html, 不罗嗦了,上代码,
页面部分【需要注意的是,为了方便大家的操作,已经按照规则填写的默认的值】
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnAdd_Click(object sender, System.EventArgs e)
{
TreeNode newNode = new TreeNode();
newNode.Text = txtChildNodeName.Text;
newNode.NavigateUrl = txtChildNodeURL.Text;
newNode.ToolTip = txtChildNodeName.Text;
tvDemo.FindNode(txtParentNode.Text).ChildNodes.Add(newNode);
lblMsg.Text = "Node Added succesfully! <br />Node Text: " + txtChildNodeName.Text +
"<br />NavigateUrl: " + txtChildNodeURL.Text +
"<br />ToolTip: " + txtChildNodeName.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to add TreeNode at runtime?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color: Red">
Dynamically adding TreeNode</h2>
<asp:Label ID="lblMsg" runat="server" Text="Type a Parent Node: "></asp:Label>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="tvDemo" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<br />
<asp:Label ID="lblParentNode" runat="server" Text="Type a Parent Node: "></asp:Label><asp:TextBox
ID="txtParentNode" Text="Home/Login" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblChildNodeUrl" runat="server" Text="Type a new child node URL: "></asp:Label>
<asp:TextBox ID="txtChildNodeURL" Text="http://www.asp.net" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblChildNodeName" runat="server" Text="Type a new child node name: "></asp:Label>
<asp:TextBox ID="txtChildNodeName" Text="ASP.NET" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add Node" OnClick="btnAdd_Click" />
</div>
</form>
</body>
</html>
Web.sitemap 文件:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode title="Home" description="Home" url="Default.aspx" >
<siteMapNode title="Login">
</siteMapNode>
<siteMapNode title="Members" description="Members" url="test/test2.aspx" >
<siteMapNode title="My Account" description="My Account" url="test/test3.aspx" />
<siteMapNode title="Products" description="Products" url="test/test4.aspx" />
</siteMapNode>
</siteMapNode>
</siteMap>
如有写的不好的地方,请帮我指出; 如果您有更好的方法,也请不吝啬,共享下,谢谢了先!
最近我遇到朋友问我,如何动态的在现有的TreeView控件上添加节点的问题,我找到了一些国外的站点,的确有些参考的代码,但是写的都不是太详细。于是我稍微花了点时间,整理了下,就算是和我以前写的那篇呼应一下吧,不过这篇有点单薄,就一篇,但是实用!如果没有读过上一篇的,强烈建议读一读!上一篇的地址是:/article/4871095.html, 不罗嗦了,上代码,
页面部分【需要注意的是,为了方便大家的操作,已经按照规则填写的默认的值】
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnAdd_Click(object sender, System.EventArgs e)
{
TreeNode newNode = new TreeNode();
newNode.Text = txtChildNodeName.Text;
newNode.NavigateUrl = txtChildNodeURL.Text;
newNode.ToolTip = txtChildNodeName.Text;
tvDemo.FindNode(txtParentNode.Text).ChildNodes.Add(newNode);
lblMsg.Text = "Node Added succesfully! <br />Node Text: " + txtChildNodeName.Text +
"<br />NavigateUrl: " + txtChildNodeURL.Text +
"<br />ToolTip: " + txtChildNodeName.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to add TreeNode at runtime?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color: Red">
Dynamically adding TreeNode</h2>
<asp:Label ID="lblMsg" runat="server" Text="Type a Parent Node: "></asp:Label>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<asp:TreeView ID="tvDemo" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<br />
<asp:Label ID="lblParentNode" runat="server" Text="Type a Parent Node: "></asp:Label><asp:TextBox
ID="txtParentNode" Text="Home/Login" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblChildNodeUrl" runat="server" Text="Type a new child node URL: "></asp:Label>
<asp:TextBox ID="txtChildNodeURL" Text="http://www.asp.net" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblChildNodeName" runat="server" Text="Type a new child node name: "></asp:Label>
<asp:TextBox ID="txtChildNodeName" Text="ASP.NET" runat="server"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add Node" OnClick="btnAdd_Click" />
</div>
</form>
</body>
</html>
Web.sitemap 文件:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode title="Home" description="Home" url="Default.aspx" >
<siteMapNode title="Login">
</siteMapNode>
<siteMapNode title="Members" description="Members" url="test/test2.aspx" >
<siteMapNode title="My Account" description="My Account" url="test/test3.aspx" />
<siteMapNode title="Products" description="Products" url="test/test4.aspx" />
</siteMapNode>
</siteMapNode>
</siteMap>
如有写的不好的地方,请帮我指出; 如果您有更好的方法,也请不吝啬,共享下,谢谢了先!
相关文章推荐
- 【原】母版页、皮肤、导航 那点事 Master Pages Themes and Navigation Controls FAQ
- Working with Data in ASP.NET 2.0 :: Master Pages and Site Navigation
- [web referrence] Sequence that events are raised for Pages, UserControls, MasterPages and HttpModules
- 【ASP.NET Step by Step】之三 Master Pages and Site Navigation
- VS2005web应用程序项目教程(5)Using Master Pages and Site Navigation
- Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages
- Metabuilders.Webcontrols.Masterpages 各控件的执行流程
- Providing Descendant and Lateral Navigation 提供下一代和横向导航
- 海洋工作室——网站建设专家:Calling JavaScript from ASP.NET Master Page and Content Pages - Part II
- Customizing themes and skins -- modified jsp pages list.
- Calling JavaScript from ASP.NET Master Page and Content Pages
- Metabuilders.Webcontrols.Masterpages应用的一点理解
- Master Pages and JavaScript document.getElementById
- ASP.NET 2.0 MasterPages and FindControl()
- 【原】Changing the Themes and MasterPage Dynamically
- Events in ASP.NET Master and Content Pages
- 什么是MetaBuilders.WebControls.MasterPages.ContentContainer
- Providing Ancestral and Temporal Navigation 设计高效的应用导航
- Passing Information Between Content and Master Pages .
- How to Add ASP.NET User Controls To Master Pages or Page Layouts