首页 > 代码库 > epoint:TreeView

epoint:TreeView

Epoint.Web.UI.WebControls2X.EpointTreeNode 

 

思路:就是使用递归


RootNodeText 根节点名称
RootNodeUrl 根节点路径
ShowRootNode 是否显示根节点

OnTreeNodePopulate 动态添加子节点事件 如果节点的表明node.PopulateOnDemand = 

true;那么这是一个动态添加的节点

 

 

一层节点

 

<epoint:TreeView ID="TreeView1" Target="main1" SearchAtClient="false" runat="server" ShowRootNode="true" RootNodeText="所有商品" RootNodeUrl="Record_List.aspx">    </epoint:TreeView>      protected void Page_Load(object sender, EventArgs e)        {            this.CurrentLeftPosition = "选择商品";            this.CurrentRightPosition = "商品列表";            this.CurrentPosition = "商品管理";            if (!Page.IsPostBack)                BindTree();        }        protected void BindTree()        {                       DataView dvCommunityInfo = new DB_Commodity().Select();            Epoint.Web.UI.WebControls2X.EpointTreeNode node;            for (int i = 0; i < dvCommunityInfo.Count; i++)            {                node = new EpointTreeNode();                node.Text = dvCommunityInfo[i]["Name"].ToString();                node.Value = dvCommunityInfo[i]["RowGuid"].ToString();                 node.NavigateUrl = "Record_List.aspx?CommidityGuid=" + node.Value;                TreeView1.Nodes.Add(node);            }        }    

技术分享

 

 

 

两层节点

public partial class XMTree : BaseContentPage_UsingMasterWithTree    {        protected void Page_Load(object sender, EventArgs e)        {            if (!Page.IsPostBack)            {                this.CurrentLeftPosition = "项目信息";                this.CurrentRightPosition = "项目信息";                this.CurrentPosition = "项目信息";                BindXMTreeData();            }        }        public void BindXMTreeData()        {            TreeView1.RootNodeText = "各类型项目";  //获取根节点文本             AddTopNodes();        }        private void AddTopNodes()        {            EpointTreeNode node;            string sqlGCValue = http://www.mamicode.com/string.Format(@"select ItemValue,ItemText from VIEW_CodeMain_CodeItems where CodeName=‘{0}‘", "项目库工程类型");            DataView dv = Epoint.MisBizLogic2.DB.ExecuteDataView(sqlGCValue);            DataView dvTemp;            for (int i = 0; i < dv.Count; i++)            {                node = new EpointTreeNode();                node.Text = Convert.ToString(dv[i]["ItemText"]);                node.Value = Convert.ToString(dv[i]["ItemValue"]);                string sqlXMtype = string.Format(@"select ItemValue,ItemText from VIEW_CodeMain_CodeItems where CodeName=‘{0}‘ and ItemValue like ‘" + Convert.ToString(dv[i]["ItemValue"]) + "%‘", "项目库项目类型");                dvTemp = Epoint.MisBizLogic2.DB.ExecuteDataView(sqlXMtype);                TreeView1.Nodes.Add(node);                if (dvTemp.Count > 0)                    expandChildNodes(node, dvTemp);     //实时加载子节点            }        }        /// <summary>        /// 递归绑定子节点        /// </summary>        /// <param name="parentNode"></param>        /// <param name="dv"></param>        private void expandChildNodes(EpointTreeNode parentNode, DataView dv)        {            EpointTreeNode node;             string fullItemText = "";            string[] TextArr;            for (int i = 0; i < dv.Count; i++)            {                node = new EpointTreeNode();                fullItemText = Convert.ToString(dv[i]["ItemText"]);                if (fullItemText.Contains(""))                {                    TextArr = fullItemText.Split();                    node.Text = TextArr[1];                }                else                {                    node.Text = Convert.ToString(dv[i]["ItemText"]);                }                node.Value = Convert.ToString(dv[i]["ItemValue"]);                node.NavigateUrl = "NodeWeightConfigTree.aspx?projecttype=" + node.Value + "&firstnodename=" + node.Text;                parentNode.ChildNodes.Add(node); //添加子节点            }        }     }

 技术分享

 

epoint:TreeView