/// <summary> /// Retrieve a list of albums that are in the heirarchical path between the specified album and a node in the treeview. /// The node that is discovered as the ancestor of the album is assigned to the existingParentNode parameter. /// </summary> /// <param name="treeview">The treeview with at least one node added to it. At least one node must be an ancestor of the /// specified album.</param> /// <param name="album">An album. This method navigates the ancestors of this album until it finds a matching node in the treeview.</param> /// <param name="existingParentNode">The existing node in the treeview that is an ancestor of the specified album is assigned to /// this parameter.</param> /// <returns>Returns a list of albums where the first album (the one returned by calling Pop) is a child of the album /// represented by the existingParentNode treeview node, and each subsequent album is a child of the previous album. /// The final album is the same album specified in the album parameter.</returns> private static Stack <IAlbum> GetAlbumsBetweenTopLevelNodeAndAlbum(ComponentArt.Web.UI.TreeView treeview, IAlbum album, out TreeViewNode existingParentNode) { if (treeview.Nodes.Count == 0) { throw new ArgumentException("The treeview must have at least one top-level node before calling the function GetAlbumsBetweenTopLevelNodeAndAlbum()."); } Stack <IAlbum> albumParents = new Stack <IAlbum>(); albumParents.Push(album); IAlbum parentAlbum = (IAlbum)album.Parent; albumParents.Push(parentAlbum); // Navigate up from the specified album until we find an album that exists in the treeview. Remember, // the treeview has been built with the root node and the first level of albums, so eventually we // should find an album. If not, just return without showing the current album. while ((existingParentNode = treeview.FindNodeById(parentAlbum.Id.ToString(CultureInfo.InvariantCulture))) == null) { parentAlbum = parentAlbum.Parent as IAlbum; if (parentAlbum == null) { break; } albumParents.Push(parentAlbum); } // Since we found a node in the treeview we don't need to add the most recent item in the stack. Pop it off. albumParents.Pop(); return(albumParents); }
protected void Page_Load(object sender, EventArgs e) { string strBookChapterId = Request.QueryString.Get("id"); ItemBLL objItemBll = new ItemBLL(); string strItemTypeID = Request.QueryString.Get("itemTypeID"); if (!string.IsNullOrEmpty(strBookChapterId)) { ComponentArt.Web.UI.TreeView tvBookChapterChapter = new ComponentArt.Web.UI.TreeView(); BookChapterBLL bookChapterBLL = new BookChapterBLL(); IList <RailExam.Model.BookChapter> bookChapterList = bookChapterBLL.GetBookChapterByBookID(int.Parse(strBookChapterId)); if (bookChapterList.Count > 0) { TreeViewNode tvn = null; foreach (RailExam.Model.BookChapter bookChapter in bookChapterList) { if (bookChapter.IsMotherItem) { continue; } tvn = new TreeViewNode(); tvn.ID = bookChapter.ChapterId.ToString(); tvn.Value = bookChapter.ChapterId.ToString(); if (Request.QueryString.Get("item") != null && Request.QueryString.Get("item") == "no") { tvn.Text = bookChapter.ChapterName; } else { int n = objItemBll.GetItemsByBookChapterIdPath(bookChapter.IdPath, Convert.ToInt32(strItemTypeID)); if (n > 0) { tvn.Text = bookChapter.ChapterName + "(" + n + "题)"; } else { tvn.Text = bookChapter.ChapterName; } } tvn.ToolTip = bookChapter.ChapterName; string strflag = Request.QueryString.Get("flag"); if (strflag != null && (strflag == "2" || strflag == "1")) { tvn.ShowCheckBox = true; } if (Request.QueryString.Get("state") != null) { tvn.Checked = Convert.ToBoolean(Request.QueryString.Get("state")); } else { if (Request.QueryString.Get("StrategyID") != null) { string str = "," + Request.QueryString.Get("StrategyID") + ","; if (str.IndexOf("," + tvn.ID + ",") != -1) { tvn.Checked = true; } } } tvn.Attributes.Add("isChapter", "true"); tvn.ImageUrl = "~/App_Themes/" + StyleSheetTheme + "/Images/TreeView/Chapter.gif"; if (bookChapter.ParentId == 0) { tvBookChapterChapter.Nodes.Add(tvn); } else { tvBookChapterChapter.FindNodeById(bookChapter.ParentId.ToString()).Nodes.Add(tvn); } } } Response.Clear(); Response.ClearHeaders(); Response.ContentType = "text/xml"; Response.Cache.SetNoStore(); string strXmlEncoding = string.Empty; try { strXmlEncoding = System.Configuration.ConfigurationManager.AppSettings["CallbackEncoding"]; } catch { strXmlEncoding = "gb2312"; #if DEBUG System.Diagnostics.Debug.WriteLine("Error Accessing Web.Config File!\r\n" + "Using \"gb2312\"!"); #endif } if (string.IsNullOrEmpty(strXmlEncoding)) { strXmlEncoding = "gb2312"; #if DEBUG System.Diagnostics.Debug.WriteLine("CallbackEncoding Empty in Web.Config File!\r\n" + "Using \"gb2312\"!"); #endif } else { try { System.Text.Encoding enc = System.Text.Encoding.GetEncoding(strXmlEncoding); } catch { #if DEBUG System.Diagnostics.Debug.WriteLine("Invalid Encoding in Web.Config File!\r\n" + "Using \"gb2312\"!"); #endif strXmlEncoding = "gb2312"; } } Response.Write("<?xml version=\"1.0\" encoding=\"" + strXmlEncoding + "\" standalone=\"yes\" ?>\r\n" + tvBookChapterChapter.GetXml()); Response.Flush(); Response.End(); } }
// 手动绑定KNOWLEDGE TreeView private void KnowledgeTreeNodeBind(int?postID, string whereClause, TreeViewNode tvNode) { ComponentArt.Web.UI.TreeView virtualTree = new ComponentArt.Web.UI.TreeView(); KnowledgeBLL knowledgeBLL = new KnowledgeBLL(); IList <RailExam.Model.Knowledge> knowledgeList; if (String.IsNullOrEmpty(whereClause)) { knowledgeList = knowledgeBLL.GetKnowledges(); } else { knowledgeList = knowledgeBLL.GetKnowledgesByWhereClause(whereClause, "level_num, order_index"); } if (knowledgeList.Count > 0) { TreeViewNode tvn = null; foreach (RailExam.Model.Knowledge knowledge in knowledgeList) { tvn = new TreeViewNode(); tvn.ID = knowledge.KnowledgeId.ToString(); tvn.Value = postID == null ? String.Empty : postID.ToString(); tvn.Text = knowledge.KnowledgeName; tvn.ToolTip = knowledge.KnowledgeName; if (knowledge.ParentId == 0) { if (tvNode == null) { this.tvKnowledge.Nodes.Add(tvn); } else { virtualTree.Nodes.Add(tvn); } } else { try { if (tvNode == null) { tvKnowledge.FindNodeById(knowledge.ParentId.ToString()).Nodes.Add(tvn); } else { virtualTree.FindNodeById(knowledge.ParentId.ToString()).Nodes.Add(tvn); } } catch { tvKnowledge.Nodes.Clear(); return; } } } if (tvNode != null) { foreach (TreeViewNode node in virtualTree.Nodes) { tvNode.Nodes.Add(node); } } } }
public static void BuildComponentArtTreeView(ComponentArt.Web.UI.TreeView tvTargetTree, IList list, string strIdProperty, string strParentIdProperty, string strTextProperty, string strTooltipProperty, string strValueProperty, string strNavigateUrlProperty, string strImageUrlProperty, string strTarget) { ComponentArt.Web.UI.TreeViewNode node = null; if (list.Count > 0) { Type objType = list[0].GetType(); string strParentId = string.Empty; foreach (object o in list) { node = new TreeViewNode(); // ID if (string.IsNullOrEmpty(strIdProperty)) { throw new Exception("树节点ID属性不能为空!"); } node.ID = objType.GetProperty(strIdProperty).GetValue(o, null).ToString(); // ParentId if (string.IsNullOrEmpty(strParentIdProperty)) { throw new Exception("树节点父ID属性不能为空!"); } strParentId = objType.GetProperty(strParentIdProperty).GetValue(o, null).ToString(); // Text if (string.IsNullOrEmpty(strTextProperty)) { throw new Exception("树节点Text属性不能为空!"); } node.Text = objType.GetProperty(strTextProperty).GetValue(o, null).ToString(); // Tooltip if (!string.IsNullOrEmpty(strTooltipProperty)) { node.ToolTip = objType.GetProperty(strTooltipProperty).GetValue(o, null).ToString(); } // Value if (!string.IsNullOrEmpty(strValueProperty)) { node.Value = objType.GetProperty(strValueProperty).GetValue(o, null).ToString(); } else { node.Value = objType.GetProperty(strValueProperty).GetValue(o, null).ToString(); } // NavigateUrl if (!string.IsNullOrEmpty(strNavigateUrlProperty)) { node.NavigateUrl = objType.GetProperty(strNavigateUrlProperty).GetValue(o, null).ToString(); } // ImageUrl if (!string.IsNullOrEmpty(strImageUrlProperty)) { node.ImageUrl = objType.GetProperty(strImageUrlProperty).GetValue(o, null).ToString(); } // Target if (!string.IsNullOrEmpty(strTarget)) { node.Target = objType.GetProperty(strTarget).GetValue(o, null).ToString(); } // Append node if (strParentId == "0") {// Root node tvTargetTree.Nodes.Add(node); } else { tvTargetTree.FindNodeById(strParentId).Nodes.Add(node); } } } }