Solved

NavigateURL does not remember what you've selected in a Treeview

Posted on 2006-11-30
35
1,112 Views
Last Modified: 2008-03-03
I really need somones help who has good knowledge in ASP.NET treeview. I'm using VS2005/C#

I have a treeview control, that is populated from a SQL db, all of the navigateURL has a URL. My problem is when I click on anyone of the URL's it dosnt remember what node I clicked on i.e. it dosnt highlight the node.

Can some one please help me in getting this to work i.e. when a user clicks on a URL, it hightlights the selected node.

Thank you
Mousemat24
0
Comment
Question by:mousemat24
  • 18
  • 12
  • 3
35 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18054034
Are you talking about something like SmartNavigation, when you use the Go Back button on the browser?

Bob
0
 

Author Comment

by:mousemat24
ID: 18054705
No TheLearnedOne.

I have a treeview, all the nodes have a navigateURL prop assigned to it, so that when a user clicks on the selectednode, it opens up a new page. But the problem I'm having is the selected node isnt highlighted, so they dont know where they are in the menu?

Does that makes sense? if not, please let me know
mousemat24
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18055356
>>when a user clicks on the selectednode, it opens up a new page
Can you show me how you do this?

Bob
0
 

Author Comment

by:mousemat24
ID: 18055404
for (i = 0; i < tempFor1; i++)
            {
                if (Convert.ToInt32(ds.Tables[0].Rows[i]["MNU_ParentNodeID"]) == 0)
                {
               
                    TreeNode tn = new TreeNode(ds.Tables[0].Rows[i]["MNU_DisplayName"].ToString(), ds.Tables[0].Rows[i]["MNU_URL"].ToString(), "");

                    RecursivelyAddToNode(tn, Convert.ToInt32(ds.Tables[0].Rows[i]["MNU_ID"]), ds);
                    TreeView1.Nodes.Add(tn);

                }
            }

============================================================

private void RecursivelyAddToNode(TreeNode mymenuitem, int ParentID, DataSet ds)
    {
       
        DataView dv = new DataView(ds.Tables[0]);
        dv.RowFilter = ("MNU_ParentNodeID=" + ParentID.ToString());
        foreach (DataRowView r in dv)
        {
       
            TreeNode tn = new TreeNode(r["MNU_DisplayName"].ToString(), r["MNU_URL"].ToString(), "");
            mymenuitem.ChildNodes.Add(tn);
            RecursivelyAddToNode(tn, Convert.ToInt32(r["MNU_ID"]), ds);
        }
    }


==============================================================

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        string valueOfTreenode          = TreeView1.SelectedNode.Value;
        string valueOfTreenodeIndexOf   = valueOfTreenode.IndexOf("{").ToString();
        Label1.Text = TreeView1.SelectedNode.Value.ToString();

        if (Convert.ToInt16(valueOfTreenodeIndexOf) == -1)
        {
            Response.Redirect(valueOfTreenode);
        }
        else
        {
            string getUnidOutFromValue = valueOfTreenode.Substring(valueOfTreenode.LastIndexOf("{"));
            Web_Ref.WebService getContent = new Web_Ref.WebService();

            DataSet ds = new DataSet();
            ds = getContent.displayContent(getUnidOutFromValue);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                content.InnerHtml = dr["CNT_Body"].ToString();
            }            
        }        
    }


Hope that helps, really would like some help
0
 

Author Comment

by:mousemat24
ID: 18055808
TheLearnedOne

As you can see Im using a Response.Redirect(<ASPX FILE>). What I want is when a user clicks on that node it will open the page up (through the master page), and highlight the selectedNode. There must be a way to get this to work with a Response.Redirect

Thanks
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18064329
Hi, mousemat24

As I told, I'm not really working with ASP. And do not much care about points :)

As I pointed in the other toopic, when a node is in navigation mode (navigateURL is assigned), all selection events are disabled for that node.
Therefore the method 'TreeView1_SelectedNodeChanged' shouldn't be invoked at all.

Did you try to NOT assign NavigateUrl but put you url into value property? Eventually you are reading the url from the value property in your method...
0
 

Author Comment

by:mousemat24
ID: 18064434
I've tried using the value, but when you do a redirect it dosnt know what you've selected.

Please see this:

http://channel9.msdn.com/ShowPost.aspx?PostID=110278

There must be a way to do this?
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18064792
Hmmm...

I'm not good enough in ASP, I told.

However what if you e.g. try to set session variable to the url, then redirect and set the selected node from this session variable?
Does it make sense at all?
0
 

Author Comment

by:mousemat24
ID: 18064940
I've done that, no luck, really need some help on this question

Thanks
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18064955
I give up.

Still check that navigateURL prop is set to blank string for ALL nodes. Otherwise I believe select mode is never working...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18067894
Have you set the SelectedNodeStyle.ForeColor/BackColor for the TreeView?

Bob
0
 

Author Comment

by:mousemat24
ID: 18068130
TheLearnedOne

the problem is, if the selected item is deep within a menu, it wont expand the menu, so if I can get that to work, maybe getting the SelectedNodeStyle.ForeColor/BackColor might work ok. This is really doing my brains in!! :-)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18068233
If you don't set the SelectedNodeStyle, then you won't see the selected node, in order to verify that it is working.

Bob
0
 

Author Comment

by:mousemat24
ID: 18068538
Just done thie Bob

TreeView1.SelectedNodeStyle.BackColor = System.Drawing.Color.Aqua;

It dosnt work when I have a Response.Redirect

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18068846
1) Are you using master pages?

2) When you do a Response.Redirect, is the TreeView still visible?

3) If you are using Response.Redirect, and not master pages, then usually the TreeView would no longer be visible, unless you have some other kind of magic.

Bob
0
 

Author Comment

by:mousemat24
ID: 18068880
1) I'm using a masterpage
2) It is visible, but the menu gets collapsed, so my selectednode isnt highlighted
3) No magic - using a master page

Annoying problem isnt it
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 18069021
>>It is visible, but the menu gets collapsed, so my selectednode isnt highlighted
Can you explain this a little more, please?  How does it get collapsed?

Bob
0
 

Author Comment

by:mousemat24
ID: 18069934
Bob, I've set the menu prop to CollapseAll

TreeView1.CollapseAll();

The reason being I will have alot of menu options, so I want to Collapse it. As I mentioned it works with the rest of the menuNodes i.e. It opens up the correct menu and remembers what you clicked on.

When I'm pulling out information from SQL, I place the content into a literal control, content.innerHTML = <FROM SQL>

But there are other menus that point to another page i.e. ASPX. Because of this I have to use Response.Redirect, theres where it stops working.

Hope thats clear?
If not please let me know
mousemat24
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18076408
If you don't collapse the TreeView, does it highlight the node correctly?

Bob
0
 

Author Comment

by:mousemat24
ID: 18076822
No it dosnt Bob, it dosnt work with any response.redirect
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18076929
Does it work with Server.Transfer?  Do you need Response.Redirect?

Bob
0
 

Author Comment

by:mousemat24
ID: 18077266
Nope sorry, I tried that too :-(
0
 

Author Comment

by:mousemat24
ID: 18084392
Any other stuff I can do Bob?
Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18084487
You could try MaintainScrollPositionOnPostback  in the @Page directive:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TreeViewExample.aspx.cs" Inherits="TreeViewExample" MaintainScrollPositionOnPostback="true" %>

Bob
0
 

Author Comment

by:mousemat24
ID: 18084621
TheLearnedOne

That too dont work, I placed that in one of my ASPX file that uses the Response.Redirect

:-(
0
 

Author Comment

by:mousemat24
ID: 18092638
Hi Bob

I think I found the answer!!!!

Go here and download the ZIP file

http://blog.binaryocean.com/2006/01/19/SaveTreeViewNodesExpansionCollapseStateCSAndVB.aspx

It expands, but I cant figure out how to highlight the selectedNode. Do you thanks you can help me?

thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 18100614
Are you asking about how to do this?

   TreeNode node = this.treeView1.Nodes[0];
   node.Select();

Bob
0
 

Author Comment

by:mousemat24
ID: 18110540
Bob

Did you try the URL, that clearly show the problem, i.e. the selected node isnt highlighted, Can you help in getting the hightlighted node color to change

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18113967
Let's revisit an old comment:

Did you set the TreeView.SelectedNodeStyle with that new code?

Bob
0
 

Author Comment

by:mousemat24
ID: 18114008
I've implemented the code from:

http://blog.binaryocean.com/2006/01/19/SaveTreeViewNodesExpansionCollapseStateCSAndVB.aspx

It dosnt hightlight the TreeView.SelectedNodeStyle, The problem I'm having is that, I dont know where to palce the code in the CS file. Its way to complicating for me, do you think you can look into it for me Bob?

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18158789
No, unfortunately I have deadlines to meet, and I don't have the time.  I was hoping that this would be a simple solution, but it has turned out to be that.

Bob
0
 

Author Comment

by:mousemat24
ID: 18207378
ok Bob

Thanks for helping out anyway
Mousemat24
0
 

Author Comment

by:mousemat24
ID: 18318094
Even though this problem never got sorted out, I'd like to give you the points TheLearnedOne for helping out, but I dont know what to accept?

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now