通讯录系统总结:这个通讯录系统的效果是父窗体放两个iframe,左边的iframe里存放的是树型目录,右边iframe里存放的是该目录下的子目录和目录下的所有联系人。当点击左边的树节点时,右边将获得对应的数据,这种效果,我想大部分的OA系统都是这样的实现的,左边是目录,右边是页面,左右实现联动。很经典的做法,这里总结一下,希望对大家有帮助。
父窗体页面放两个iframe
<html xmlns=" [url]http://www.w3.org/1999/xhtml[/url] " >
<head runat="server">
    <title>主框架</title>
    <script language="javascript">
function closethis()
{
document.all.dir.style.display='none';
}
function openthis()
{
document.all.dir.style.display='';
}
</script>
</head>
<body>
<table border="0" width="100%" cellpadding="0" class="main-table">
<tr>
         <td align="left" id=dir style="width:23%">  
   <iframe id="menu" name="menu" src="PublicCategory.aspx" class="inset-table" width="300" height="600" frameborder="NO" border="0" framespacing="0"></iframe> //左边菜单,这里将放一棵树型目录                                                                                                                                                                                            
      </td>
       <td width="2%" align=center><a href="javascript:closethis();"><=</a><br><br><br><a href="javascript:openthis();">=></a></td>
      <td align="left" style="width:75%">
      <iframe id="Right" name="Right" src="PublicContectPersonList.aspx" class="outset-table" width="100%" height="600" frameborder="NO" border="1" framespacing="0" noresize align=middle></iframe>// 右边详细页面,点击左边的树型目录得到  
      </td>                                                                                                                                                                                    
   </tr>                                                                                                                                                                                          
</table>
</body>
</html>
左边目录子页面PublicCategory.aspx
前台:
<html xmlns=" [url]http://www.w3.org/1999/xhtml[/url] " >
<head runat="server">
    <title>公有目录</title>
      <link href="../../../Skin/<%=Session["_SkinPath"] %>/CSS/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form1" runat="server">
    <div style="width:100%;">
        <table class="main-table" style="width: 283; height: 100%">
             <tr class="title">
                    <td align="left">目录列表:</td>
                </tr>
            <tr class="line-even" >
                <td style="width: 100%" valign="top">
                   <asp:TreeView ID="tvCategory" runat="server" Height="560" ImageSet="Contacts" Width="283">
                        <Nodes>
                            <asp:TreeNode Text="公用通讯录" Value="公用通讯录">
                                <asp:TreeNode Text="新建节点" Value="新建节点">
                                    <asp:TreeNode Text="新建节点" Value="新建节点"></asp:TreeNode>
                                </asp:TreeNode>
                                <asp:TreeNode Text="新建节点" Value="新建节点"></asp:TreeNode>
                            </asp:TreeNode>
                        </Nodes>
                       <SelectedNodeStyle BackColor="#C0FFFF" />
                    </asp:TreeView>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>
后台:
public partial class PublicCategory : System.Web.UI.Page
    {
        DataTable dt = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                int ispublic =1;//表示公有
                dt = Classes.BusinessObject.TXLBiz.GetAllCategory(ispublic, Convert.ToInt32(Session["_userId"].ToString()));//调用业务逻辑层方法得到所有的目录
                this.initTree(dt);
            }
        }
        /// <summary>
        /// 初始化树
        /// </summary>
        /// <param name="dt">取得所有的目录</param>
        private void initTree(DataTable dt)
        {
            this.tvCategory.Nodes.Clear();//先清理原先的
            if (dt!=null&&dt.Rows.Count == 0) return;
            DataRow[] Rows = dt.Select("parentID=0");
            if (Rows.Length == 0) return;
            foreach (DataRow row in Rows)
            {
                    TreeNode tNode = new TreeNode();
                    tNode.Value = row["categoryID"].ToString();
                    tNode.Text = row["title"].ToString();
                    tNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + tNode.Value + "";
                    tNode.Target = "Right";//指向父窗体右边的那个iframe
                    this.tvCategory.Nodes.Add(tNode);
                    createChildNode(tNode, tNode.Value);
             }
        }

        /// <summary>
        /// 创建子节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="strParentNo"></param>
        private void createChildNode(TreeNode node, string strParentNo)
        {

            DataRow[] Rows = dt.Select("parentID='" + Convert.ToInt32(strParentNo) + "'");
            foreach (DataRow row in Rows)
            {
                TreeNode childNode = new TreeNode();
                childNode.Value = row["categoryID"].ToString();
                childNode.Target = "Right";//指向父窗体右边的那个iframe
                childNode.Text = row["title"].ToString();
                childNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + childNode.Value + "";
                node.ChildNodes.Add(childNode);
                createChildNode(childNode, row["categoryID"].ToString());
            }
        }
}
右边详细信息页面:PublicContectPersonList.aspx
这个页面就没什么好介绍的,通过刚才节点 tNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + tNode.Value + "";
childNode.NavigateUrl = "PublicContectPersonList.aspx?categoryID=" + childNode.Value + "";
传过来的节点id去数据库取数据绑定到GridView就可以