最近发现了csdn论坛发了很多的帖子,都是问关于如何实现csdn论坛这种效果的,也就是左边一个treeview树目录,然后点击节点可以链接到右边的页面。这个问题其实并不是很难,下面我将把代码贴出来,并略作讲解,希望达到抛砖引玉的效果。
首先说一下结构。整个登陆进去是一个frameset页面,准确的说是个框架,左边的框架里面是有treeview的页面,右边的框架里面是目标内容页
我先贴上我的frameset的代码
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
ForumDefault.aspx.cs
"
Inherits
=
"
CSD.Repository.ForumUI.ForumDefault
"
%>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< title > 欢迎来到CSD论坛 </ title >
</ head >
< frameset id = " sidebar_content " cols = " 230, * " frameborder = " 1 " border = " 6 " framespacing = " 5 "
bordercolor = " #A1C7F9 " >
< frame name = " sidebarFrame " src = " TreeLeft.aspx " scrolling = " no " frameborder = " 1 " />
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< title > 欢迎来到CSD论坛 </ title >
</ head >
< frameset id = " sidebar_content " cols = " 230, * " frameborder = " 1 " border = " 6 " framespacing = " 5 "
bordercolor = " #A1C7F9 " >
< frame name = " sidebarFrame " src = " TreeLeft.aspx " scrolling = " no " frameborder = " 1 " />
其次,我贴上左边的树的一部分的数据绑定的代码:
public static TreeNode InitOtherTreeNode(TreeNode node)
... {
TreeNode nodeChange = new TreeNode();
Guid parentForumId = new Guid(node.Value);
BLL.Forum forumBLL = new CSD.Repository.BLL.Forum();
IList<ForumInfo> fInfo = forumBLL.GetForumsByParentForumId(parentForumId);
foreach(ForumInfo info in fInfo)
...{
TreeNode newNode = new TreeNode();
newNode.Text = info.ForumName.ToString();
newNode.Value = info.ForumId.ToString();
newNode.Target = "ContentFrame";
newNode.NavigateUrl = @"forumMain.aspx?forumId="+newNode.Value;
node.ChildNodes.Add(newNode);
nodeChange=newNode;
}
return nodeChange;
}
大家可以看到这个newNode.Targe的值就是右边的框架名,而NavigateUrl的值就是所要跳转的地址以及所要传递的参数,也就是querystring,大家注意通配符。
好了就说这么多了,有什么问题可以一起探讨