0

尝试创建可视化 Web 部件以将 SharePoint 2010 讨论板呈现为树状视图。我可以将所有主题作为父节点取回,并将每个主题的所有回复作为子节点取回,但不能使用层次结构。所以所有回复(甚至是对早期回复的回复)都在同一节点级别。有一个名为 ThreadIndex 的属性可用于跟踪层次结构上的回复处于什么级别(是第一个回复还是对第一个回复的回复或{对第一个回复的回复的回复}等。两行是threadingindex值。你可以看到第一个回复有一定的threading index值,回复它有它的threading index值,并附加了一些随机字符串。

这就是它的样子: 我的样子 http://www.resizr.com/resized/d2eb.jpg

这就是我希望它看起来的样子: Desired http://www.resizr.com/resized/8249.jpg

有人可以给我一些提示吗?

public partial class HDRDiscussionTreeUserControl : UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        List<string> allTopics = new List<string>();
        List<string> allreplies = new List<string>();
        List<int> allpids = new List<int>();
        HDRDiscussionTV.Nodes.Clear();          
        TreeNode node;
        SPSite currentSite = SPContext.Current.Site;
        SPWeb web = currentSite.RootWeb;
        //Get the Discussion list
        SPList lst = web.Lists["SP2017Discussion"];

        SPQuery query0 = new SPQuery();
        //get all topics
        query0.Query = "<Where><IsNotNull><FieldRef Name=\"Title\" /></IsNotNull></Where>";
        SPListItemCollection col = lst.GetItems(query0);

        foreach (SPListItem item in col)
        { 
            //listItem.Fields["Parent Folder Id"].GetFieldValueAsText(listItem["Parent Folder Id"]).ToString() 
            //string pfid = item.Fields["Parent Folder Id"].GetFieldValueAsText(item["Parent Folder Id"]).ToString();
            int id = item.ID;
            SPQuery query = new SPQuery();
            SPListItem topic = item;
            //allTopics.Add(item.Title);

            node = new TreeNode(item.Title);
            HDRDiscussionTV.Nodes.Add(node);

             SPQuery query1 = new SPQuery();
            query1.Folder = item.Folder;
             //get all replies
            SPListItemCollection relatedDiscussions = lst.GetItems(query1);
            try
            {
                if (relatedDiscussions.Count != 0)
                {
                    int n = 1;
                    TreeNode parentNode1 = node;
                    for (int i = 0; i <= relatedDiscussions.Count; i++)
                    {
                        //int parentListID = Convert.ToInt32(relatedDiscussions[i].Fields["Parent Folder Id"].GetFieldValueAsText(relatedDiscussions[i]["Parent Folder Id"]));
                        string threading = relatedDiscussions[i]["ThreadIndex"].ToString();
                        string checkthreading = relatedDiscussions[n]["ThreadIndex"].ToString();
                        node = new TreeNode(relatedDiscussions[i]["ows_TrimmedBody"].ToString()+"|" + threading + "|");
                        parentNode1.ChildNodes.Add(node);
                         n = i + 1;
                    }
                }
            }
            catch
            {
            }
        }

     }
4

1 回答 1

0

为什么不使用树视图控件? http://hamidseta.blogspot.com/2012/01/check-uncheck-all-checkbox-in-treeview.html

于 2012-10-16T17:40:41.160 回答