treeview 简单绑定

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bindtreeview();
        }
        
    }

    private void Bindtreeview()
    {
        TreeNode root = new TreeNode("首页", "shouye");
        root.NavigateUrl = "Default2.aspx";
        TreeNode nodeyingyu = new TreeNode("英语", "yingyu");
        root.ChildNodes.Add(nodeyingyu);
        nodeyingyu.NavigateUrl = "yingyu.aspx";
        TreeNode zhuanyeyingyu = new TreeNode("专业英语", "zhuanyeyingyu");
        nodeyingyu.ChildNodes.Add(zhuanyeyingyu);
        nodeyingyu.NavigateUrl = "zhuanyeyingyu.aspx";

        TreeNode nodeyuwen = new TreeNode("语文", "yuwen");
        root.ChildNodes.Add(nodeyuwen);
        TreeNode nodeshuxue = new TreeNode("数学", "shuxue");
        root.ChildNodes.Add(nodeshuxue);
        TreeNode nodezhuanye = new TreeNode("专业", "zhuanye");
        root.ChildNodes.Add(nodezhuanye);
        this.TreeView1.Nodes.Add(root);
    }
}


 

转载于:https://www.cnblogs.com/chinagg/archive/2011/11/29/3675128.html

你可能感兴趣的:(treeview 简单绑定)