473,385 Members | 1,753 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,385 software developers and data experts.

Traversing TreeView Server Control in JavaScript

BlueEagle
hi to all!

I hv added a TreeView Control on my page in Asp.net 2.0
and i want to move through the Tree in JavaScript

Anyone hv an idea
Advance Thanks

BlueEagle
Jul 30 '07 #1
7 3288
gits
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

please post an example how the tree turns out in HTML-code at the client ... i assume you want to go through the tree at the client?

kind regards
Jul 30 '07 #2
ya
i want to go through the tree on client.
Following is the HTML code of two tree nodes
i.e Root node n childNode

[HTML]<div id="ctl00_mainCopy_TvCategory" tabindex="1" class="body_text" onClick="return SendAJAXRequest('category')" style="height:100%;width:90%;">

<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><a id="ctl00_mainCopy_TvCategoryn0" href="javascript:TreeView_ToggleNode(ctl00_mainCop y_TvCategory_Data,0,document.getElementById('ctl00 _mainCopy_TvCategoryn0'),' ',document.getElementById('ctl00_mainCopy_TvCatego ryn0Nodes'))"><img src="/Portal/WebResource.axd?d=1AWafB_GTw_x5zrwUf0qOxbxUc9SpHSp etVTIkUu1aE1&amp;t=633113381376406250" alt="Collapse Root" style="border-width:0;" /></a></td><td class="ctl00_mainCopy_TvCategory_2 ctl00_mainCopy_TvCategory_4" style="white-space:nowrap;"><span class="ctl00_mainCopy_TvCategory_0 ctl00_mainCopy_TvCategory_1 ctl00_mainCopy_TvCategory_3" id="ctl00_mainCopy_TvCategoryt0">

Root</span></td>

</tr><tr style="height:0px;">
<td></td>

</tr>
</table><div id="ctl00_mainCopy_TvCategoryn0Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr style="height:0px;">
<td></td>
</tr><tr>
<td><div style="width:20px;height:1px"></div></td><td><img src="/Portal/WebResource.axd?d=1AWafB_GTw_x5zrwUf0qO_v3eFF7H5bL _Egg4IX37YA1&amp;t=633113381376406250" alt="" /></td><td class="ctl00_mainCopy_TvCategory_2 body_text ctl00_mainCopy_TvCategory_8" onmouseover="TreeView_HoverNode(ctl00_mainCopy_TvC ategory_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><a class="ctl00_mainCopy_TvCategory_0 ctl00_mainCopy_TvCategory_1 body_text ctl00_mainCopy_TvCategory_7" href="javascript:__doPostBack('ctl00$mainCopy$TvCa tegory','s1\\2')" onclick="TreeView_SelectNode(ctl00_mainCopy_TvCate gory_Data, this,'ctl00_mainCopy_TvCategoryt1');" id="ctl00_mainCopy_TvCategoryt1" style="border-style:none;font-size:1em;">

Books</a></td>
</tr><tr style="height:0px;">

<td></td>
</tr>
</table><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr style="height:0px;">
<td></td>
</tr><tr>
<td><div style="width:20px;height:1px"></div></td><td><img src="/Portal/WebResource.axd?d=1AWafB_GTw_x5zrwUf0qO_v3eFF7H5bL _Egg4IX37YA1&amp;t=633113381376406250" alt="" /></td><td class="ctl00_mainCopy_TvCategory_2 body_text ctl00_mainCopy_TvCategory_8" onmouseover="TreeView_HoverNode(ctl00_mainCopy_TvC ategory_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><a class="ctl00_mainCopy_TvCategory_0 ctl00_mainCopy_TvCategory_1 body_text ctl00_mainCopy_TvCategory_7" href="javascript:__doPostBack('ctl00$mainCopy$TvCa tegory','s1\\8')" onclick="TreeView_SelectNode(ctl00_mainCopy_TvCate gory_Data, this,'ctl00_mainCopy_TvCategoryt2');" id="ctl00_mainCopy_TvCategoryt2" style="border-style:none;font-size:1em;">Bread</a></td>
</tr><tr style="height:0px;">

<td></td>
</tr>[/HTML]

If u got an idea please tell me

thanks

BlueEagle
Jul 30 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

well ... your tree is a html-table so now we know that we may go through the html table. to get all rows you may use:

Expand|Select|Wrap|Line Numbers
  1. var table_rows = document.getElementsByTagName('tr');
  2.  
that returns you the node-list of all tr-elements in your page. now you may loop through that list and refer to childNodes of every row ... what field, value or whatever of the row is of interest for you? ... have a look at one row and tell me what you want to retrieve.

kind regards
Jul 30 '07 #4
hi ...

well ... your tree is a html-table so now we know that we may go through the html table. to get all rows you may use:

Expand|Select|Wrap|Line Numbers
  1. var table_rows = document.getElementsByTagName('tr');
  2.  
that returns you the node-list of all tr-elements in your page. now you may loop through that list and refer to childNodes of every row ... what field, value or whatever of the row is of interest for you? ... have a look at one row and tell me what you want to retrieve.

kind regards
thanks it works
but can u tell me some methods of collection object "table_rows"
like length()
actually i want to get the id of all <tr> objects
like id="ctl00_mainCopy_TvCategoryt1"
shown in above code
i need only the way that how can i move through "table_rows" by using loop
n how can i extract the required using substring or innerHTML

regards,
BlueEagle
Jul 30 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

hmmm ... that is not that easy as you might think. the node-list is only a collection of dom-nodes ... so our table_rows-list consists of [0...n] tr-nodes. probably you know that a dom-node may have childNodes appended that may be element-nodes or text-nodes. a node has attributes and properties. for example to retrieve (and alert) the id of every row you may do the following:

Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < table_rows.length; i++) {
  2.     var row = table_rows[i];
  3.  
  4.     alert(row.id);
  5. }
  6.  
of course you may use innerHTML to get everything that a row contains but when using row.childNodes you get a collection of all current childNodes of a table-row and you may loop again and ask for properties or attributes ...

kind regards
Jul 30 '07 #6
hi ...

hmmm ... that is not that easy as you might think. the node-list is only a collection of dom-nodes ... so our table_rows-list consists of [0...n] tr-nodes. probably you know that a dom-node may have childNodes appended that may be element-nodes or text-nodes. a node has attributes and properties. for example to retrieve (and alert) the id of every row you may do the following:

Expand|Select|Wrap|Line Numbers
  1. for (var i = 0; i < table_rows.length; i++) {
  2.     var row = table_rows[i];
  3.  
  4.     alert(row.id);
  5. }
  6.  
of course you may use innerHTML to get everything that a row contains but when using row.childNodes you get a collection of all current childNodes of a table-row and you may loop again and ask for properties or attributes ...

kind regards
Yee

i hv done the job. thanks
i got an idea...from ur idea

as u see HTML making the DIV and Table for each level of nodes of Tree
and there is also <a> tag for each node.
i m succeeded in getting the id's of all tree nodes by following codes
Expand|Select|Wrap|Line Numbers
  1. var table_rows = document.getElementsByTagName('a');
  2. alert(table_rows.length);
  3. var ids='Start';
  4. for (var i = 0; i < table_rows.length; i++) {
  5.     var row = table_rows[i];
  6.     ids = ids + row.id;
  7. }
  8. ids = ids + 'End';
  9.     alert(ids);
  10.  

much thanks for reponse
my ist experiance is 2 good

regards,
Jul 30 '07 #7
gits
5,390 Expert Mod 4TB
hi ...

glad you got the idea and your code working with it ;) ... come back to the forum and post your questions ... anytime ... :)

kind regards
Jul 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ravi | last post by:
i tried with MS treeview control but i am unable to implement all the requirements.This requiement like when user login will generate the menu and display it. After that we need to Add or remove...
0
by: Amir Ghezelbash | last post by:
Hello, I had a question, i am using TreeView provided with asp.net 2.0, greate control..but sadly it dosenot have drag and drop functionality..so i decided to add it my self ..i have worte the...
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
4
by: Christian Rühl | last post by:
Good Day, folks! I'm having a problem traversing an XmlDocument tree in C#. I only want to access the InnerText of the leafs and the names of their ancestors and show them in a richTextBox. But...
1
by: Victor Rodriguez | last post by:
Is there a way that I can have a client side event like oncontextmenu="showfunction();" on each node? thanks, Victor
8
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...
2
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created...
1
by: Falcula | last post by:
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.