Two questions about TreeView

Last post 06-18-2008 6:18 AM by gruenefeder. 7 replies.

Sort Posts:

  • Two questions about TreeView

    06-07-2008, 8:09 AM
    • Member
      84 point Member
    • svetsarn
    • Member since 10-13-2002, 9:00 AM
    • Posts 228

    Hello!

    Is it possible to keep the treview expanded after you have clicked a link in the treeview? I'm using SiteMap. How can I add an extern link in the SiteMap? I have tried, but the link will not show up in the treeview.

  • Re: Two questions about TreeView

    06-09-2008, 12:19 AM
    Answer

    Hi,

    svetsarn:
    Is it possible to keep the treview expanded after you have clicked a link in the treeview? I'm using SiteMap.

    You can try to refer the below sample code:

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
           if (e.Node.Parent == null)
                return;
            string strNodeValue = e.Node.Value;
            foreach (TreeNode node in e.Node.Parent.ChildNodes)
            {
                if (node.Value != strNodeValue)
                {
                    node.Collapse();
                }
                else
                {
                    node.Expand();
                }

            }    }

    svetsarn:
    How can I add an extern link in the SiteMap? I have tried, but the link will not show up in the treeview.

    You can add the extern link in the SiteMap, and it can works fine, below is out test code:

    1. SiteMap file:

    <?xml version="1.0" encoding="utf-8" ?>
    <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

     <siteMapNode url="~/Menu/Cases/Cases/case2/Default.aspx#" title="Home" description="The Home Page">
        <siteMapNode url="~/TreeView/CheckBox/masterPage/Default2.aspx" title="Our Products" description="Products that we offer">
          <siteMapNode url="~/TreeView/Cause/case1/Default.aspx" title="First Product"   description="The description of the First Product" />
          <siteMapNode title="Google" url="http://www.Google.com" description="The Google Website" roles="RoleA" />
          <siteMapNode title="Microsoft"  url="http://www.Microsoft.com" description="The Microsoft Website"  />
          <siteMapNode title="Yahoo" url="http://www.Yahoo.com" description="The Yahoo Website"  />
        </siteMapNode> 
      </siteMapNode></siteMap>

    2. The TreeView

    <asp:TreeView ID="TreeView1" runat="server" ShowLines="True"
        CollapseImageUrl="~/image/bg-search.gif"
        ExpandImageUrl="~/image/button-search.gif"
        NoExpandImageUrl="~/image/bg-search.gif"
        OnTreeNodeCollapsed="TreeView1_TreeNodeCollapsed"
        OnTreeNodeExpanded="TreeView1_TreeNodeExpanded" 
        OnDataBound="TreeView1_DataBound" LineImagesFolder="~/TreeLineImages"
        DataSourceID="SiteMapDataSource1" >
                <SelectedNodeStyle BackColor="#8080FF" />
               
            </asp:TreeView>

    Hope it helps.

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Two questions about TreeView

    06-09-2008, 6:02 AM
    • Contributor
      4,221 point Contributor
    • moredotnet
    • Member since 11-24-2006, 12:07 PM
    • Millenium City
    • Posts 781

    you can also open the external url in a new window by setting  url="javscript:window.open('http://www.yourOutGoingLink.com')" in the sitemap.

    Vishal Khanna



    ASP.NET|C#|AJAX|SQL|Design Patterns|Interview FAQs
  • Re: Two questions about TreeView

    06-09-2008, 11:06 AM
    • Member
      84 point Member
    • svetsarn
    • Member since 10-13-2002, 9:00 AM
    • Posts 228

    Thank you for your answer.

    When I try the code in the first question I got this error message " CS0123: No overload for 'TreeView1_TreeNodeExpanded' matches delegate 'System.EventHandler'" this is my code:
    <asp:TreeView ID="TreeView1"
    ExpandImageUrl="~/Graphic/folder.gif"
    OnDataBound="TreeView1_TreeNodeExpanded"
    CollapseImageUrl="~/Graphic/folder.gif"
    EnableViewState="true"
    ExpandDepth="1"
    NodeIndent="5"
    runat="server"
    CssClass="regText"
    DataSourceID="SiteMapDataSource1">
    </asp:TreeView>

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
    if (e.Node.Parent == null)
    return;
    string strNodeValue = e.Node.Value;
    foreach (TreeNode node in e.Node.Parent.ChildNodes)
    {
    if (node.Value != strNodeValue)
    {
    node.Collapse();
    }
    else
    {
    node.Expand();
    }
    }
    }

    In the second question I have tried both way, but the link will not show up in the page.

  • Re: Two questions about TreeView

    06-09-2008, 10:55 PM

    Hi,

    svetsarn:
    <asp:TreeView ID="TreeView1"
    ExpandImageUrl="~/Graphic/folder.gif"
    OnDataBound="TreeView1_TreeNodeExpanded"

    Why did you set the TreeView DataBound Event is the TreeView's TreeNodeExpanded event?

    How about try to change the TreeView Like this:

     OnTreeNodeExpanded="TreeView1_TreeNodeExpanded"  
     OnDataBound="TreeView1_DataBound"

    Hope it helps.

     

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Two questions about TreeView

    06-10-2008, 1:35 AM
    • Member
      84 point Member
    • svetsarn
    • Member since 10-13-2002, 9:00 AM
    • Posts 228

    That won't work either. I don't understand how I can set "OnDataBound = TreeView1_DataBound" when I don't have a method  "TreeView1_DataBound". I get the error message:

    CS1061: 'ASP.masterpages_mhmasterpage_master' does not contain a definition for 'TreeView1_DataBound' and no extension method 'TreeView1_DataBound' accepting a first argument of type 'ASP.masterpages_mhmasterpage_master' could be found (are you missing a using directive or an assembly reference?)

  • Re: Two questions about TreeView

    06-10-2008, 10:08 PM

    Hi,

    svetsarn:
    That won't work either. I don't understand how I can set "OnDataBound = TreeView1_DataBound" when I don't have a method  "TreeView1_DataBound".

    If you do not need the TreeView's DataBound event, you can try to delete it from the TreeView, you can only set the event that you need.

    The error message is tell us, you set the DataBound event for the TreeView, but there is not DataBound event in the codebehind.

     

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Two questions about TreeView

    06-18-2008, 6:18 AM
    • Member
      2 point Member
    • gruenefeder
    • Member since 06-18-2008, 6:08 AM
    • Posts 1

    Hey altogether,

    the code below doesn't work with sharepoint. I want to implement a tree with treeview in sharepoint. I inserted the code in my sharepoint master-file (file.master) but it doesn't work. When I navigate through the tree and click on a node, the new page is opened and the tree is closed again. I guess I have to save the state of the tree and have to load it, when the new page is loaded. But I have no idea how the implement it. I'm a newbie in ASP and sharepoint. I know ... a good combination ;-) I hope someone can help me?

    <%@Master language="C#"%>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
    <%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
    <HTML dir="<%$Resources:wss,multipages_direction_dir_value%>" runat="server" xmlns:o="urn:schemas-microsoft-com:office:office" __expr-val-dir="ltr">
    <HEAD runat="server">
     <META Name="GENERATOR" Content="Microsoft SharePoint">
     <META Name="progid" Content="SharePoint.WebPartPage.Document">
     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
     <META HTTP-EQUIV="Expires" content="0">
     <SharePoint:RobotsMetaTag runat="server"/>
     <Title ID=onetidTitle><asp:ContentPlaceHolder id=PlaceHolderPageTitle runat="server"/></Title>
     <SharePoint:CssLink runat="server"/>
     <SharePoint:Theme runat="server"/>
     <SharePoint:ScriptLink language="javascript" name="core.js" Defer="true" runat="server"/>
     <SharePoint:CustomJSUrl runat="server"/>
     <SharePoint:SoapDiscoveryLink runat="server"/>
     <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
     <SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
    </HEAD>
    <BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper(); SetVisioLinks();">

    <script type="text/c#" runat="server">

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
           if (e.Node.Parent == null)
                return;
            string strNodeValue = e.Node.Value;
            foreach (TreeNode node in e.Node.Parent.ChildNodes)
            {
                if (node.Value != strNodeValue)
                {
                    node.Collapse();
                }
                else
                {
                    node.Expand();
                }

            }    }


    </script>

    <script language="javascript" type="text/javascript">

    ...

    </script>


      <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">

    ...

     <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="0" ForeColor="Black" HoverNodeStyle-ForeColor="#D63804" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded">
        <Nodes>
          <asp:TreeNode Text="aaa">
            <asp:TreeNode Text="bbb" NavigateUrl="http://server/file1.aspx" >
             <asp:TreeNode Text="ccc" NavigateUrl="http://server/file2.aspx" />
            </asp:TreeNode>
     
    ...

     

    Thanks a lot in advance!!!

    Best, Daniel

Page 1 of 1 (8 items)