CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: Date Entered: 11/21/2009 6:18:53 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 0 Views: 7 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
"bcweed966" <>
NewsGroup User
help with the treeview...11/21/2009 6:18:53 PM

0

I am just starting to use the treeview and the sitemap together. This is a very simple sitemap and treeview.

the problem is that: according to the sitemap there is a root "home" and then there are 2 nodes "work Visa" and "skilled work visa". each of those nodes have subnodes or child nodes.


the tree view works fine in the fist level of nodes. But if I open 1 of the main nodes to expose the child nodes all is ok but if I click on a child node it navigates to that page just fine but the treeview coplapses itself and returns to the initial state where nothing is selected on it at all.

I hope I make myself clear. When you click on a main node (the 2 top ones below "home") it navigates to that page and that node changes its apearance to show that it is the selected node. If I click on the arrow next to the node then the node opens and exposes its child nodes.... but you go click on one of the child nodes it navigates to that page but the treeview retuirns to the initial not selected state all colapsed and all...

you can witness this at:

http://www.canadawelcome.ca/home.aspx?AspxAutoDetectCookieSupport=1

why?

<asp:SiteMapDataSource ID="SiteMapDataSource3" runat="server"
                        SiteMapProvider="TBH_SiteMapProvider" StartFromCurrentNode="False" />


                <asp:TreeView SkinID="MainLeftTree" ID="TreeView1" cssclass="LeftTreeViewMenu" runat="server" ImageSet="Arrows" Style="vertical-align: top; background-color: #FFE4E1; color: darkred;
        width: 100%; text-align: left; padding: 5px;" DataSourceID="SiteMapDataSource3" MaxDataBindDepth="20">
                    <ParentNodeStyle Font-Bold="False" />
                    <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                    <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
                        HorizontalPadding="0px" VerticalPadding="0px" />
                    <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
                        HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
    </asp:TreeView>

this is my site map:


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true" >
   <siteMapNode title="HOME" url="~/home.aspx">
       <siteMapNode title="WORK VISA" url="~/WorkVisas/WorkVisas.aspx">
               <siteMapNode title="JOB DESCRIPTION" url="~/WorkVisas/JobDescription.aspx" />
          </siteMapNode>
       <siteMapNode title="SKILLED WORK VISA" url="~/SkilledWorkVisas/SkileedWorkVisaGC.aspx">
         <siteMapNode title="Who can apply" url="~/SkilledWorkVisas/WhoCanApplyGC.aspx" />
         <siteMapNode title="How to apply" url="~/SkilledWorkVisas/HowToApplyGC.aspx" />
         <siteMapNode title="Simplyfied application process" url="~/SkilledWorkVisas/SimplyfiedAppGC.aspx" />
       
       </siteMapNode>
          </siteMapNode>
</siteMap>

"aquaren" <>
NewsGroup User
Re: help with the treeview...11/22/2009 1:23:36 PM

0

The treeview does not maintain the selected item when you navigate to a new page.

One way to overcome this is to put something in the url that signifies which node was selected and use that to programmatically set the selected node when the new page loads.

"Cboysworld" <>
NewsGroup User
Re: help with the treeview...11/22/2009 11:20:26 PM

0

What language are you writing in? 

"Cboysworld" <>
NewsGroup User
Re: help with the treeview...11/22/2009 11:39:04 PM

0

In C#.  Place this code in your master page .cs file
 
using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class Site_master : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        // Disable ExpandDepth if the TreeView's expand/collapse
        // state is stored in session.
        //
        if (Session["TreeViewState"] != null)
            TreeView1.ExpandDepth = -1;
    }

    protected void TreeView1_DataBound(object sender, EventArgs e)
    {
        if (Session["TreeViewState"] == null)
        {
            //
            // Record the TreeView's current expand/collapse state.
            //
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
        else
        {
            //
            // Apply the recorded expand/collapse state to the TreeView.
            //
            List<string> list = (List<string>)Session["TreeViewState"];
            RestoreTreeViewState(TreeView1.Nodes, list);
        }
    }

    protected void TreeView1_TreeNodeCollapsed(object sender, TreeNodeEventArgs e)
    {
        if (IsPostBack)
        {
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
    }

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
    {
        if (IsPostBack)
        {
            List<string> list = new List<string>(16);
            SaveTreeViewState(TreeView1.Nodes, list);
            Session["TreeViewState"] = list;
        }
    }

    private void SaveTreeViewState(TreeNodeCollection nodes, List<string> list)
    {
        //
        // Recursivley record all expanded nodes in the List.
        //
        foreach (TreeNode node in nodes)
        {
            if (node.ChildNodes != null && node.ChildNodes.Count != 0)
            {
                if (node.Expanded.HasValue && node.Expanded == true && !String.IsNullOrEmpty(node.Text))
                    list.Add(node.Text);
                SaveTreeViewState(node.ChildNodes, list);
            }
        }
    }

    private void RestoreTreeViewState(TreeNodeCollection nodes, List<string> list)
    {
        foreach (TreeNode node in nodes)
        {
            //
            // Restore the state of one node.
            //
            if (list.Contains(node.Text))
            {
                if (node.ChildNodes != null && node.ChildNodes.Count != 0 && node.Expanded.HasValue && node.Expanded == false)
                    node.Expand();
            }
            else
            {
                if (node.ChildNodes != null && node.ChildNodes.Count != 0 && node.Expanded.HasValue && node.Expanded == true)
                    node.Collapse();
            }

            //
            // If the node has child nodes, restore their state, too.
            //
            if (node.ChildNodes != null && node.ChildNodes.Count != 0)
                RestoreTreeViewState(node.ChildNodes, list);
        }
    }
}


 

4 Items, 1 Pages 1 |< << Go >> >|


Free Download:







treeview depending on roles?

master page object focus and content pages

master page, smooth page to page transitions...

sort treeview nodes

master page load

nested master pages

master pages and images

treeview and sitemap

is it possible to set hyperlink colors in the master page?

control menu usng javascript?

master page + theming = the controls collection cannot be modified because the control contains code blocks

asp.net masterpages and menus integrating with prebuilt templates??

master page theme issues

how to: change the menu control by the correct user role

treeview html

master page with login view and login status

wizard (webform) writes twice to database.

how to rotate text on an asp.net page

subfolder, web.sitemap and selected

web.sitemap, sitemapdatasource and single link?

menu and xmldatasource.data of a string

content page of master?

menu & frames - help

asp.net code giving me error that it cannot be connected to sql server

asp:menu conflicts with iframe

how to include media property in css style sheets included in themes folder?

accessing a linqdatacontrol from a content page (master pages)?

custom sitemapprovider - require login for various pages

how do i set master.page image button

treeview - show node as selected without posting back

editing in treeview

disabling the asp:button in masterpage wben we press enter key

page lifecycle

hide nodes from the menu

imagemap control - onclick() server-side event is not firing ? !!!

menu image next to selected item

menu control formatting

raisepostbackevent and masterpages

previous page refrence problem with masterpage.

strange problem with menu control, it breaks up in certain pages

multiple master pages using different css files

multiple sitemaps for webcrawlers question

set control properties on a master page

tree view question

treeview bound to sitemapdatasource navigate and expand

bizarre master page table "interference"

sitemappath not refreshing node title

sitemap question

pre-built themes

1px or 2px space at top of menu

   
  Privacy | Contact Us
All Times Are GMT