前台代码 注意 一定要加上Target="contentFrame"否则跳转的时候 跳不到内容框架Page Language="C#" AutoEventWireup="true" CodeFile="Left.aspx.cs" Inherits="Left" %>
后台代码using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Configuration;using System.Data;using System.IO;using NetBuild.Common;using NetBuild.Models;using NetBuild.Bussiness;using System.Linq;public partial class Left : System.Web.UI.Page{ ////// /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { TreeNode tmpNode; lbLoginUser.Text = Session["LoginName"].ToString(); AddTreeNode(-1, (System.Web.UI.WebControls.TreeNode)null); } } public DataTable bind() { string str1 = "select * from Common_Menu "; DataSet myds = new DataSet(); myds = SQLHelper.GetDataSet(str1); return myds.Tables[0]; } protected void AddTreeNode(int ParentMenuID, System.Web.UI.WebControls.TreeNode pNode) { DataTable dt = bind(); DataView dv = new DataView(dt); //过滤parentId,得到当前节点的所有子节点 dv.RowFilter = "ParentMenuID=" + ParentMenuID; //foreach (DataRow b in dt.Rows) //{ // ParentMenuID = Convert.ToInt32(b["ParentMenuID"].ToString()); //} foreach (DataRowView drv in dv) { if (ParentMenuID == -1) { System.Web.UI.WebControls.TreeNode tn1 = new System.Web.UI.WebControls.TreeNode(); tn1.Text = drv["MenuName"].ToString(); //节点上要显示的名称 tn1.Value = drv["MenuID"].ToString(); tn1.ImageUrl = drv["Icon"].ToString(); tn1.NavigateUrl = drv["MenuUrl"].ToString(); //点击节点名称,跳转到指定url页面 tvMenu1.Nodes.Add(tn1); //将根节点加入到TreeView中去 tn1.Expanded = true; //tn1.SelectAction = TreeNodeSelectAction.Expand; tn1.ShowCheckBox = false; //递归调用 AddTreeNode(Int32.Parse(drv["MenuID"].ToString()), tn1); } else { System.Web.UI.WebControls.TreeNode tn2 = new System.Web.UI.WebControls.TreeNode(); tn2.Text = drv["MenuName"].ToString(); tn2.Value = drv["MenuID"].ToString(); tn2.ImageUrl = drv["Icon"].ToString(); tn2.NavigateUrl = drv["MenuUrl"].ToString(); pNode.ChildNodes.Add(tn2); tn2.ShowCheckBox = false; tn2.Expanded = true; //递归调用 AddTreeNode(Int32.Parse(drv["MenuID"].ToString()), tn2); } } } }