473,725 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Treeview, loosing selected node after navigate, need help from

Hello,

I have a treeview control, when i select a item i navigate to url. But
selected node is lost, it reset itself, loosing state.

I post my code here. Thanks in advance.

<script language="javas cript">
var selectedPageId = 1;
function OnPageClick(pag eId)
{
selectedPageId = pageId;
parent.location = "default.aspx?i d="+pageId;
}
<%=javascript %>

</script>
<asp:TreeView ID="SubMenuTree " EnableClientScr ipt="true"
EnableViewState ="true" ExpandDepth="1"
OnSelectedNodeC hanged="nodeSel ect" OnTreeNodePopul ate="PopulateNo de"
runat="server" ImageSet="XPFil eExplorer" NodeIndent="15" >
<ParentNodeStyl e Font-Bold="False" />
<HoverNodeSty le Font-Underline="True " ForeColor="#666 6AA" />
<SelectedNodeSt yle BackColor="#B5B 5B5" Font-Underline="Fals e"
HorizontalPaddi ng="0px"
VerticalPadding ="0px" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Blac k"
HorizontalPaddi ng="2px"
NodeSpacing="0p x" VerticalPadding ="2px" />
<Nodes>
<asp:TreeNode Text="Root" SelectAction="S elect"
PopulateOnDeman d="True" Value="0"/>
</Nodes>
</asp:TreeView>

protected void PopulateNode(Ob ject sender, TreeNodeEventAr gs
e)
{

// Call the appropriate method to populate a node at a
particular level.
switch (e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateTopLeve lNodes(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateChilder n(e.Node);
break;
default:
// Do nothing.
break;
}

}
private void PopulateTopLeve lNodes(TreeNode node)
{

Selago.Business Layer.Service service = new
Selago.Business Layer.Service() ;
PageList = service.GetPage s();

foreach(iPage page in PageList)
{
if(page.ParentI D == 0)
{
TreeNode TopLevel = new TreeNode();

TopLevel.Text = page.PageName;
TopLevel.Value = page.ID.ToStrin g();

// Add root node to TreeView
TopLevel.Popula teOnDemand = true;
TopLevel.Select Action =
TreeNodeSelectA ction.SelectExp and;
node.ChildNodes .Add(TopLevel);

}
}
}

private void PopulateChilder n(TreeNode node)
{

Selago.Business Layer.Service service = new
Selago.Business Layer.Service() ;
ChildrenList =
service.GetChil drenPages(Int32 .Parse(node.Val ue));

foreach (iPage page in ChildrenList)
{
TreeNode newNode = new TreeNode();

newNode.Text = page.PageName;
newNode.Value = page.ID.ToStrin g();

// Set additional properties for the node.
newNode.SelectA ction =
TreeNodeSelectA ction.SelectExp and;

// Add the new node to the ChildNodes collection of
the parent node.
node.ChildNodes .Add(newNode);

DataSet ChildrensSub = new DataSet();
int ChildrensSubCou nt =
service.GetChil drenPages(Int32 .Parse(newNode. Value)).Count;

if (ChildrensSubCo unt 0)
{
PopulateChilder n(newNode);
}

}
}
protected void nodeSelect(obje ct sender, EventArgs e)
{
javascript = "OnPageClic k(" +
SubMenuTree.Sel ectedNode.Value + ");";
}

Dec 4 '07 #1
1 3505

"Falcula" <je************ @yahoo.sewrote in message
news:5a******** *************** ***********@v4g 2000hsf.googleg roups.com...
Hello,

I have a treeview control, when i select a item i navigate to url. But
selected node is lost, it reset itself, loosing state.

The selected node is stored in the viewstate. Viewstate is only used on
postbacks, not redirects. So when you redirect the user to a new page, the
viewstate is not used on the new page and that's why the selected node is
"lost".

If you want to "remember" the selected node you'll need to pass it in the
query string, post data, or keep it on the server somehow (e.g. session).

Dec 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2758
by: Steve | last post by:
Visual Studio 2003 .NET / C# I have a treeview object on a form which acts as the main menu controller for my application. the treeview is always in sight, and the form it is on acts as the main container for the whole application. All other screens are UserControls, which get added and removed from/to the main form, when the user clicks an item on the tree view. I thought the best way to handle navigating around would be to define...
4
7598
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
6
4933
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
3
2255
by: Shawn | last post by:
Hi. I'm working with the TreeView control in my ASP.NET 1.1 application. I have a problem I haven't been able to figure out. When I click on a node (not expand), whether it's a parent node, a child node or a leaf node then a DataGrid is populated based on the node's ID property. If I expand a node then the DataGrid is not populated. This works fine. The problem is that this doesn't work if I collapse the tree. If I collapse the tree...
2
9790
by: Claus | last post by:
Hello, I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards the treeview is collapsed and the node isn't selected. Expanding and selecting the node via code in the load event works, but how do I achieve, that the treeview scrolls down to the selected node? Thanks for any help Claus
8
12772
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
18
15375
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and click to make multiple selections. Then when I simply click one item, all previous selections are gone. Thanks in advance.
0
1899
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the current selection and stuff in the tree. I post my code here, any idea ?
2
4400
by: govolsbaby | last post by:
Hi All I've got a treeview with checkboxes. I want the user to be able to toggle the checkbox by click on the checkbox OR by clicking on the node text. So I've added an afterselect event handler to get the selected node and change the .Checked property of the selected node as appropriate, which works to change the .Checked status when the user FIRST clicks on the text of a particular node.
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.