如何建立一个ASP.NET的TreeView的划痕......? [英] How to build an ASP.NET TreeView From Scratch...?

查看:108
本文介绍了如何建立一个ASP.NET的TreeView的划痕......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ASP.NET建立一个嵌套/线程评论系统。我不知道PHP的家伙是怎么做的。它更难比最初想象。

I am trying to build a nested/threaded comment system in ASP.NET. I don't know how the PHP guys do it. Its much harder than first imagined.

我想我damnedest获得分层数据输出到用户,但它不工作。

I am trying my damnedest get Hierarchical data to output to the user, but its not working.

我有文本,ITEMID和的parentID表。

I have a table with text, a itemID and a parentID.

我要显示在树视图格式的信息,但asp.net的标准控制是行不通的......

I want to display the information in a tree view format, but asp.net's standard control just doesn't work...

任何人都可以点我这如何输出正确的方向成树视图。我曾尝试嵌套中继器,从codebehind直出的HTML建设和TreeView控件。

Can anyone point me in the right direction of how to output this into a treeview. I have tried nesting repeaters, straight out html building from codebehind and the treeview control.

我还没有找到一个解决办法...任何人都可以帮我?

I still haven't found a solution... Can anyone help me out?

推荐答案

很快,由头(不能在VS2k8立即检查),我会做这样的事情使用LINQ to SQL

Quickly, by head (could not check in VS2k8 now), I would do it something like this using Linq to SQL

private void BuildTree()
{
   List<Item> items = from item in dataContext.Items
                      select item;

   List<Item> rootItems = items.FindAll(p => p.ParentID == null );

   foreach ( Item item in rootItems )
   {
      TreeViewNode tvi = new TreeViewNode(item.text);
      BuildChildNodes(tvi, items, item.ID);
      YourTreeNodeName.Nodes.Add(tvi);
   }   
}

private void BuildChildNodes(TreeViewNode parentNode, List<Item> items, long parentID)
{
   List<Item> children = items.FindAll ( p => p.ParentID = parentID );
   foreach( Item item in children)
   {
      TreeViewNode tvi = new TreeViewNode(item.text);
      parentNode.Nodes.Add(tvi);
      BuildChildNodes(tvi, items, item.ID);         
   }
}

这篇关于如何建立一个ASP.NET的TreeView的划痕......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆