returning treeview element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ralf Riedel
    New Member
    • Apr 2011
    • 2

    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

    Code:
        <script type="text/javascript">
            function GetValue() { //should be invoked upon checking an item
                var src = window.event != window.undefined ? window.event.srcElement : evt.target;
                var obj = window.event.srcElement;
                var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
                if (isChkBoxClick) {
                    var parentTable = GetParentByTagName("table", src);
                    var name = tvTaxon_Data.selectedNodeID.value;
                    alert(document.getElementById(name)); //just for testing
                    //now store in session variable
                }
            }
        </script>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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

    Comment

    • Ralf Riedel
      New Member
      • Apr 2011
      • 2

      #3
      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:


      Code:
       <script type="text/javascript">
              function GetName(evt) {
                  var src = window.event != window.undefined ? window.event.srcElement : evt.target;
                  var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
                  var nodeText = src.innerText || src.innerHTML;
                  if (isChkBoxClick) {
                      alert("hello " + nodeText + " hi"); //returns 'hello'+ blank+ 'hi', so 'nodetext' is not set
                  }
      	  }
      </script>

      In the .cs file:

      Code:
              protected void Page_Load(object sender, EventArgs e)
              {            
                  tvTaxon.Attributes.Add("onclick", "GetName(event)");
                  //tvTaxon.Attributes.Clear();
                  InitTaxon(); //this populate the tree from a database
              }

      Comment

      Working...