473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Set selected node in Treeview control in ASP:NET 2.0 ? Anyone know this ?

Hello,

Iam using Treeview control in asp.net 2.0. But have a problem.

I use NavigateUrl BUT then viewstate is lost when clicked on a link i
the menu. And the selected node is lost.

Then i have to set the selected node manually, how can i do it ? i have
tried but without luck :(
I have posted my menu code here.
namespace DayDream.Admin.UC
{
public partial class AdminMenu : DayDreamBaseUserControl
{
public string SelectedURL;

protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}

protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{

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

}
private void PopulateTopLevelNodes(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();

for (int x = 0; x <
basePage.GetAllPages().Tables[0].Rows.Count; x++)
{
if
(basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
<= 0)
{

TreeNode TopLevel = new TreeNode();

//TopLevel.NavigateUrl =
basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
"?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.NavigateUrl =
"../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
+ "?id=" +
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.Text =
basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
TopLevel.Value =
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();

// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.ChildNodes.Add(TopLevel);
}

}

}
private void PopulateChildern(TreeNode node)
{

DayDreamBasePage basePage = new DayDreamBasePage();

DataSet Childrens = new DataSet();
Childrens =
basePage.GetChildrenPages(Int32.Parse(node.Value)) ;

for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
{

TreeNode newNode = new TreeNode();
newNode.NavigateUrl = "../../" +
Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
Childrens.Tables[0].Rows[y]["PageID"].ToString();
newNode.Text =
Childrens.Tables[0].Rows[y]["PageName"].ToString();
newNode.Value =
Childrens.Tables[0].Rows[y]["PageID"].ToString();

// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;

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

DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;

if (ChildrensSubCount > 0)
{
PopulateChildern(newNode);
}

}
}
}
}
Thanks
Jeppe

Dec 26 '05 #1
1 2663
On Page_Load event you are not checking if Page isPostBack

If Not (Page.IsPostBack) {
DataBind();
}

Sandeep

"je************@yahoo.se" wrote:
Hello,

Iam using Treeview control in asp.net 2.0. But have a problem.

I use NavigateUrl BUT then viewstate is lost when clicked on a link i
the menu. And the selected node is lost.

Then i have to set the selected node manually, how can i do it ? i have
tried but without luck :(
I have posted my menu code here.
namespace DayDream.Admin.UC
{
public partial class AdminMenu : DayDreamBaseUserControl
{
public string SelectedURL;

protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}

protected void PopulateNode(Object sender, TreeNodeEventArgs e)
{

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

}
private void PopulateTopLevelNodes(TreeNode node)
{
DayDreamBasePage basePage = new DayDreamBasePage();

for (int x = 0; x <
basePage.GetAllPages().Tables[0].Rows.Count; x++)
{
if
(basePage.GetAllPages().Tables[0].Rows[x]["ParentPageID"].ToString().Length
<= 0)
{

TreeNode TopLevel = new TreeNode();

//TopLevel.NavigateUrl =
basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString() +
"?id=" + basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.NavigateUrl =
"../../"+basePage.GetAllPages().Tables[0].Rows[x]["Template"].ToString()
+ "?id=" +
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();
TopLevel.Text =
basePage.GetAllPages().Tables[0].Rows[x]["PageName"].ToString();
TopLevel.Value =
basePage.GetAllPages().Tables[0].Rows[x]["PageID"].ToString();

// Add root node to TreeView
TopLevel.PopulateOnDemand = true;
TopLevel.SelectAction =
TreeNodeSelectAction.SelectExpand;
node.ChildNodes.Add(TopLevel);
}

}

}
private void PopulateChildern(TreeNode node)
{

DayDreamBasePage basePage = new DayDreamBasePage();

DataSet Childrens = new DataSet();
Childrens =
basePage.GetChildrenPages(Int32.Parse(node.Value)) ;

for (int y = 0; y < Childrens.Tables[0].Rows.Count; y++)
{

TreeNode newNode = new TreeNode();
newNode.NavigateUrl = "../../" +
Childrens.Tables[0].Rows[y]["Template"].ToString() + "?id=" +
Childrens.Tables[0].Rows[y]["PageID"].ToString();
newNode.Text =
Childrens.Tables[0].Rows[y]["PageName"].ToString();
newNode.Value =
Childrens.Tables[0].Rows[y]["PageID"].ToString();

// Set additional properties for the node.
newNode.SelectAction =
TreeNodeSelectAction.SelectExpand;

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

DataSet ChildrensSub = new DataSet();
int ChildrensSubCount =
basePage.GetChildrenPages(Int32.Parse(newNode.Valu e)).Tables[0].Rows.Count;

if (ChildrensSubCount > 0)
{
PopulateChildern(newNode);
}

}
}
}
}
Thanks
Jeppe

Dec 28 '05 #2

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

Similar topics

0
by: Banda RamaNarsi Reddy | last post by:
Hi, We have a Datagrid and we are using third party tool treeview control(ASP.NET(C#)). it's like we have to add treeview control in the datagrid dynamically, such that each cell will have a tree...
3
by: J Gao | last post by:
Can anyone give me a suggestion for the best TreeView Web Control in the market? Thanks. Jie
1
by: Handi | last post by:
I found the TreeView control in ASP.net 2.0 is very powerful, can i use is in my 1.1 web application? if can . how to do? Thanks!
0
by: MarkD | last post by:
I have an ASP.NET (VB.NET) application that calls all VB6 COM DLL via Interop. The DLL uses functionality contained in a Custom OCX Control (Also VB6) that in turn contains a standard TreeView...
3
by: jesper_lofgren | last post by:
Hi, I have two usercontrols one menu control that use ASP.NET 2.0 Treeview control, then a main usercontrol for showing the selected URL in a Iframe. The problem is when i raise the...
0
by: fiefie.niles | last post by:
In ASP.Net 1.1 (using Visual Studio 2003), in the toolbox I can not find TreeView control (like in the Windows Form). Does TreeView control for ASP (webform) exist ? Thanks
4
by: Ted Ngo | last post by:
Hi All, I am using treeview control in asp.net 2.0. this is my treeview: ZZZZZ NNNNNN HHHHHHH KKKKKKK AAAA
1
by: Luqman | last post by:
I am using Oracle Database Scott.Emp table with Parent/Child relation keys. How can I fill the ASP.Net 2.0 TreeView Control using Sql Data Source. As the TreeView just uses xmldatasource, is it...
0
by: Janarthanan Lakshmanan | last post by:
Hi to all, We have a treeview control in ASP.Net 2.0.We used in our project.We faced some problem while check checkbox. We want to check the parent node check box, if the respective child node was...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.