I have read on this forum a couple of "how to" implement the ComponentArt CategoryTreeView and it works.
My problem is that no mather how I try to modify the different parameters I cant get it to look like this "Bare Bones" version I want:
http://www.componentart.com/webui/demos ... Form1.aspx
In my installations of Able 7 (latest build) i allready have a image folder with all the images (App_themes/images/ComponentArt/TreeView/lines), I just don't now how to modify the parameters correct. Or do I need something else?
Anyone who can give me some tips how to modify this code to make it look like the example link above?
Best regards, Thomas
CategoryTreeView.ascx
Code: Select all
<%@ Control Language="C#" ClassName="CategoryTreeView" EnableViewState="false" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<%--
<conlib>
<summary>Displays the categories in your store in a treeview.</summary>
<param name="CacheDuration" default="60">Number of minutes the category tree will remain cached in memory. Set to 0 to disable caching.</param>
</conlib>
--%>
<script runat="server">
int _CacheDuration = 60;
public int CacheDuration
{
get { return _CacheDuration; }
set { _CacheDuration = value; }
}
protected void Page_Init(object sender, EventArgs e)
{
InitializeCategoryTree();
}
private void InitializeCategoryTree()
{
TreeView1.ShowLines = false;
TreeView1.ImagesBaseUrl = "/App_Themes/" + Page.Theme + "/images/CategoryTreeView/";
TreeView1.CssClass = "CatTreeView";
TreeView1.NodeCssClass = "CatTreeNode";
TreeView1.SelectedNodeCssClass = "CatSelectedTreeNode";
TreeView1.HoverNodeCssClass = "CatHoverTreeNode";
GetCategoryTreeNodes();
// Specify the current category
int categoryId = PageHelper.GetCategoryId();
TreeViewNode node = TreeView1.FindNodeById(categoryId.ToString());
if (node != null)
{
node.TemplateId = "SelectedCategoryTemplate";
node.Expanded = true;
EnsureTreeNodeVisible(node);
}
}
private void GetCategoryTreeNodes()
{
string cacheKey = "53741CA849784C8DA262F53638A2A38F";
string categoryNodes = null;
if (_CacheDuration > 0)
{
// Check to see if category treeview is in the cache
categoryNodes = Cache.Get(cacheKey) as string;
}
if (categoryNodes == null)
{
GetCategoryNodesRecursive(0, TreeView1.Nodes);
Cache.Insert(cacheKey, TreeView1.GetXml(), null, DateTime.Now.AddMinutes(_CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);
}
else
{
// Load Nodes from the cached xml string
TreeView1.LoadXml(categoryNodes);
}
}
private void GetCategoryNodesRecursive(int categoryId, TreeViewNodeCollection nodes)
{
TreeViewNode node;
CategoryCollection subcategories = CategoryDataSource.LoadForParent(categoryId, true);
foreach (Category subcat in subcategories)
{
node = new TreeViewNode();
node.ID = subcat.CategoryId.ToString();
node.Text = subcat.Name;
node.NavigateUrl = subcat.NavigateUrl;
node.ImageUrl = subcat.ThumbnailUrl;
nodes.Add(node);
GetCategoryNodesRecursive(subcat.CategoryId, node.Nodes);
}
}
private void EnsureTreeNodeVisible(TreeViewNode node)
{
TreeViewNode currentNode = node.ParentNode;
while (currentNode != null)
{
currentNode.Expanded = true;
currentNode = currentNode.ParentNode;
}
}
</script>
<asp:Panel ID="MainPanel" runat="server" CssClass="section">
<asp:Panel ID="HeaderPanel" runat="server" CssClass="header">
<h2 class="header"><asp:Localize ID="HeaderTextLabel" runat="server" Text="Categories"></asp:Localize></h2>
</asp:Panel>
<asp:Panel ID="TreePanel" runat="server" CssClass="content">
<ComponentArt:TreeView id="TreeView1"
DragAndDropEnabled="false"
NodeEditingEnabled="false"
KeyboardEnabled="true"
CssClass="CatTreeView"
NodeCssClass="CatTreeNode"
SelectedNodeCssClass="CatSelectedTreeNode"
HoverNodeCssClass="CatHoverTreeNode"
DefaultImageWidth="16"
DefaultImageHeight="16"
ExpandCollapseImageWidth="15"
ExpandCollapseImageHeight="15"
NodeIndent="16"
ItemSpacing="3"
NodeLabelPadding="3"
CollapseImageUrl="exp.gif"
ExpandImageUrl="col.gif"
ParentNodeImageUrl="folders.gif"
LeafNodeImageUrl="folder.gif"
ShowLines="false"
EnableViewState="false"
runat="server">
<Templates>
<ComponentArt:NavigationCustomTemplate id="SelectedCategoryTemplate">
<Template>
<b><%# DataBinder.Eval(Container.DataItem, "Text") %></b>
</Template>
</ComponentArt:NavigationCustomTemplate>
</Templates>
</ComponentArt:TreeView>
</asp:Panel>
</asp:Panel>