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

returning treeview element

Hi all,

I am writing an asp.net application in C# where I use a treeview. That treeview gets populated upon initialization from an SQL Server database. The treeview has checkboxes visible for all items to allow multiple selections by the user.

After the user selects items from the treeview, I generate an SQL query that will retrieve data from the database and make it available to the user. What I need is a way to store treeview selections in a session variable for later use to build the query.

Because clicking on the treeview checkboxes does not generate a postback, I need to write a javascript code to do that. Here’s where I need help. I am not familiar with javascript and have attempted to write something to the effect of what I need (see code below), but it is not working as I expected. I was able to find and successfully use javascript code to check/uncheck all items and do similar things, but what I need is something much simpler. Can anyone help me or direct me to a source? Thx,

Ralf

Expand|Select|Wrap|Line Numbers
  1.  
  2.     <script type="text/javascript">
  3.         function GetValue() { //should be invoked upon checking an item
  4.             var src = window.event != window.undefined ? window.event.srcElement : evt.target;
  5.             var obj = window.event.srcElement;
  6.             var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
  7.             if (isChkBoxClick) {
  8.                 var parentTable = GetParentByTagName("table", src);
  9.                 var name = tvTaxon_Data.selectedNodeID.value;
  10.                 alert(document.getElementById(name)); //just for testing
  11.                 //now store in session variable
  12.             }
  13.         }
  14.     </script>
  15.  
Apr 23 '11 #1
2 1945
gits
5,390 Expert Mod 4TB
you already have a handler that is called onclick of your checkboxes? if so you might use a simple XMLHttpRequest to update the session ... tell me whether you have the handler already that you can use and/or whether you would need help with the request ...

kind regards
Apr 27 '11 #2
Yes, I’d need all the help I can get. I have a handler in the .cs file and the javascript file as indicated below. Thx for your reply,

Ralf

In the .aspx file:


Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript">
  2.         function GetName(evt) {
  3.             var src = window.event != window.undefined ? window.event.srcElement : evt.target;
  4.             var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
  5.             var nodeText = src.innerText || src.innerHTML;
  6.             if (isChkBoxClick) {
  7.                 alert("hello " + nodeText + " hi"); //returns 'hello'+ blank+ 'hi', so 'nodetext' is not set
  8.             }
  9.       }
  10. </script>
  11.  

In the .cs file:

Expand|Select|Wrap|Line Numbers
  1.         protected void Page_Load(object sender, EventArgs e)
  2.         {            
  3.             tvTaxon.Attributes.Add("onclick", "GetName(event)");
  4.             //tvTaxon.Attributes.Clear();
  5.             InitTaxon(); //this populate the tree from a database
  6.         }
  7.  
Apr 27 '11 #3

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

Similar topics

14
by: delerious | last post by:
I need to determine an element's width and height in pixels (not including padding, border, and margin) in Javascript. The element will not have width or height styles specified. In Mozilla, I...
1
by: Scott Navarre | last post by:
Hello, I was wondering if there is a way (through JavaScript) to find out which of the form's elements currently has focus -- like returning an element name or index number... Thanks in...
3
by: feel | last post by:
Goin' crazy with this recursive function ported from delphi... I send a string like DirA/ DirB /DirC but i get in the treeView each one in a new node.Cant get the child node....!! -DirA -DirB...
2
by: Aaron Corcoran | last post by:
I posted this under the webcontrols area as well, however, I didn't receive any feedback, so please pardon my redundant post. Dear Group, My coworker has been working on a project that uses...
2
by: C. A. Kelly | last post by:
I have seen lots of posts for populating a treeview from a XML file but haven't been able to find/figure out how to go from a treeview to XML.
3
by: musosdev | last post by:
Hi guys How do I get the new TreeView (asp2.0) to load something in an Iframe? I've setup a NaviagateUrl and set the Target property to the name of the Iframe, but it still tries to load a new...
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
1
by: Ron M. Newman | last post by:
Hi, I have a living UI treeView element. I need to push a button and begin adding nodes to it recursively. There are a lot of nodes to add to the tree. My questions is: is there a mechanism by...
4
by: Henrik Dahl | last post by:
I have the fragment below as contents of a <Gridelement. The idea is that if the checkbox is checked the <TreeViewelement should only span one instead of two columns. When I check the checkbox the...
0
by: stevobenno | last post by:
I have spent two days unsuccessfully trying to add cascading checkbox functionality to the IE Treeview in 1.1. Has anyone managed to do this.? I did manage to get some javascript that by all...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.