SharePoint讨论列表TreeView Visual webpart

时间:2012-10-16 17:18:58

标签: jquery list sharepoint treeview

尝试创建可视webpart以将SharePoint 2010讨论板呈现为树视图。 我可以将所有主题作为父节点和每个主题的所有回复作为子节点而不是层次结构返回。因此,所有回复(甚至是对早期回复的回复)都在同一节点级别上。有一个名为ThreadIndex的属性,可用于跟踪层次结构上的回复级别(无论是第一个回复还是回复第一个回复或{回复第一个回复的回复}等。两行是threadingindex值。你可以看到第一个回复如何具有一定的线程索引值并且回复它的线程索引值附加了一些随机字符串..

这就是它的样子: what mine looks like 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
            {
            }
        }

     }

1 个答案:

答案 0 :(得分:0)