要实现如图上面的功能,其中每个栏目都能添加子类,并且没有限制的,能无限添加。
   之前用了treeview只是拖出来界面写死的,查了一些看的绑定的也都有级别限制,不能无限绑,添加倒是没什么,就是把这些都绑到前面显示的时候这个循环不知道怎么弄。求助~

解决方案 »

  1.   

    这个tree估计是要自己写了,自己实现这些功能
      

  2.   

    gridview,repeater中嵌入treeview
    http://topic.csdn.net/u/20100719/10/6ad767ee-b192-4e86-ac31-737c192020f5.html
      

  3.   

    Tree绑定就用递归,但是,增删改你就自己写呀,这是最好的方法啊
      

  4.   

    这几天打断了,弄了点别的,现在又回头重新弄。
    找了个http://apps.hi.baidu.com/share/detail/2240056 仿照他这个来写。
    但是到这一步tn.PopulateOnDemand = (Convert.ToInt32(dr["childnodecount"]) > 0 ? true : false); 
    我这一字段的确大于0,但是始终为false,很郁闷,不知道怎么回事。
    这是我前台的页面:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="class.aspx.cs" Inherits="xx.Admin.news._class" %><!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></title>
        <link href="../Style/all.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="text-align: center;">
            <asp:TreeView ID="tk" runat="server" ShowLines="true"
                ShowExpandCollapse="true" OnTreeNodePopulate="tk_TreeNodePopulate">
            </asp:TreeView>
        </div>
        </form>
    </body>
    </html>这个是后台的 public partial class _class : System.Web.UI.Page
        {        protected int i=0;
            protected string s;        protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindRoot();
                }
            }
            protected void BindRoot()
            {            DataTable root = getTable(s_sql(0));            BindNode(root, tk.Nodes);
            }        protected void BindSub(int parent_id, TreeNode parent_node)
            {
                DataTable sub = getTable(s_sql(parent_id));
                BindNode(sub, parent_node.ChildNodes);
            }
            protected void tk_TreeNodePopulate(object sender, TreeNodeEventArgs e)
            {
                BindSub(Convert.ToInt32(e.Node.Value), e.Node);
            }
            private void BindNode(DataTable dt, TreeNodeCollection nodes)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = dr["Name"].ToString();
                    tn.Value = dr["NK_ID"].ToString();                nodes.Add(tn);
                    tn.PopulateOnDemand =( Convert.ToInt32(dr["PID"]) > 0 ? true : false);
                    tn.SelectAction = TreeNodeSelectAction.Expand;
                }
            }        protected static string s_sql(int id)
            {
                string s=string.Empty;
                return s= "select * from TBNewsKind where PID=" + id;
            }
            protected static DataTable getTable(string sql)
            {
                OleDbConnection conn=new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
                conn.Open();
                using (conn)
                {
                    OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
                    DataSet ds = new DataSet();
                    oda.Fill(ds);
                    return ds.Tables[0];
                }
            }        
        }求各位帮忙开下怎么搞的。回11L你那个图片看不到。
      

  5.   

     //创建父节点
        public void CreateTreeView()
        {
           //查询父节点
            IList<Pro_type> list = Pro_typeManage.GetParentType();
            foreach (Pro_type pt in list)
            {
                TreeNode nodes = CreateNode(pt.Id, ptname);             CreateChildNode(pt.Id, nodes);
                 node.ChildNodes.Add(nodes);
                node.Expanded = true;
            }
        }
        //创建TreeNode
        public static TreeNode CreateNode(int id, string names)
        {
            TreeNode node = new TreeNode();
            node.Text = names;
            node.Value = Convert.ToString(id);
            return node;
        }
           // 创建子节点
        public void CreateChildNode(int parentid, TreeNode PNode)
        {
            //父节点查询子节点
            IList<Pro_type> list = Pro_typeManage.GetChildTypeByParentId(parentid);
            foreach (Pro_type pt in list)
            {
                TreeNode noe = CreateNode(pt.Id, ptname); //递归
                PNode.ChildNodes.Add(noe);                  }
        }
      

  6.   


     //创建父节点
        public void CreateTreeView()
        {
           //查询父节点
            IList<Pro_type> list = Pro_typeManage.GetParentType();
            foreach (Pro_type pt in list)
            {
                TreeNode nodes = CreateNode(pt.Id, ptname);             CreateChildNode(pt.Id, nodes);
                 node.ChildNodes.Add(nodes);//求教磊哥,看不懂这里的node是哪转过来的
                node.Expanded = true;
            }
        }