Click here to Skip to main content
15,885,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have a treeview with following data for ex

-Asp.net
-Controls
-Textbox
+validators

so when user clicks on the textbox node i have to show in a label the complete details of the textbox and that label should come under the textbox only.


thanks in advance
Posted

Hi

Hi Check this code once for displaying properties with respective control

ASP.NET
<asp:TreeView ID="TreeView1" runat="server"
           onselectednodechanged="TreeView1_SelectedNodeChanged">
       <Nodes>
         <asp:TreeNode Text="TextBox"  >

         </asp:TreeNode>
         <asp:TreeNode Text="DropdownList"></asp:TreeNode>
         <asp:TreeNode Text="Button"></asp:TreeNode>
       </Nodes>
       </asp:TreeView>


In code behind file you need to write below code
C#
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
  {
      showControlDetails.Visible = true;
      TreeView rootview = (TreeView)sender;
      Control txtchck =null;

      switch (rootview.SelectedNode.Text)
      {
          case ("TextBox"):
              txtchck = new TextBox();
              break;
          case ("DropdownList"):
              txtchck = new DropDownList();
              break;
          case ("Button"):
              txtchck = new Button();
              break;

      }
      if (txtchck != null)
      {
          Type controlType = txtchck.GetType();

          PropertyInfo[] properties = controlType.GetProperties();

          foreach (PropertyInfo controlProperty in properties)
          {
              TreeNode tnd = new TreeNode();
              tnd.Text = controlProperty.Name;
              rootview.SelectedNode.ChildNodes.Add(tnd);

          }
      }
  }


Here this time it is just for adding sub nodes

I'll modify it and post here to show as tooltip

And you should import namespaces System.Reflection;
Here i did only for textbox you can modify it to fulfill your requirement
and i hope you know how to add nodes to treenode

All the Best
 
Share this answer
 
v2
Comments
lakshmichawala 10-Apr-12 5:08am    
Hi murali thanks for ur help .but the textbox properties should come in a label but not added to the treeview
Muralikrishna8811 10-Apr-12 5:11am    
you mean whenever user selects node i.e TextBox

details should be displayed in list of labels in another side

i'm i right
Muralikrishna8811 10-Apr-12 5:13am    
you can show in labels under textbox node

for this you need to add all labels to textbox node ha
Muralikrishna8811 10-Apr-12 5:19am    
Hi place this code Under foreach loop

treenode tnd=new treenode();
tnd.text=controlProperty.Name;
treeview1.nodes[2].add(tnd);
lakshmichawala 10-Apr-12 5:23am    
hi murali . when user clicks on the textbox the details of the textbox should come like howover...simply i can say like a tooltip.but i cannot user tooltip there
Hi,

This is Updated Solution for displaying popup on client click

ASP.NET
<asp:treeview id="TreeView1" runat="server" xmlns:asp="#unknown">
      <nodes>
        <asp:treenode text="TextBox">

        </asp:treenode>
        <asp:treenode text="DropdownList"></asp:treenode>
        <asp:treenode text="Button"></asp:treenode>
      </nodes>
      </asp:treeview>

XML
<div id="showControlDetails1" style="   background-color:#136012;   position:fixed;left:500px;top:600px; border-color:Red;">
     dsfsdfsdfsdf
    </div>


After that you need to add javascript file

JavaScript
$(document).ready(function () {

    jQuery.fn.elementlocation = function () {
        var curleft = 0;
        var curtop = 0;

        var obj = this;

        do {
            curleft += obj.attr('offsetLeft');
            curtop += obj.attr('offsetTop');

            obj = obj.offsetParent();
        } while (obj.attr('tagName') != 'BODY');


        return ({ x: curleft, y: curtop });
    };
    $("#TreeView1 a").each(function () {
        $(this).click(function (eventObj) {

            var location = $(this).elementlocation();
            var x = eventObj.pageX - location.x;
            var y = eventObj.pageY - location.y;
            $.get("default8.aspx", { methodtype: "getProperties", controlname: $(this).text() }, function (data) {
                $("#showControlDetails1").html(data);
                $("#showControlDetails1").css('left', x);
                $("#showControlDetails1").css('top', y);
                $("#showControlDetails1").show();
            });

            return false;
        });
    });

    $("#showControlDetails1").mouseleave(function () {
        $("#showControlDetails1").hide();
    });
});


Here you need to change default8.aspx to your page name

And code behind file needs following code

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           if (Request.QueryString["methodtype"] != null)
           {
               if (Request.QueryString["methodtype"].ToString() == "getProperties")
               {
                   Response.Clear();
                   string cntname = Request.QueryString["controlname"].ToString();
                   Control txtchck = null;
                   string stresult = "";
                   switch (cntname)
                   {
                       case ("TextBox"):
                           txtchck = new TextBox();
                           break;
                       case ("DropdownList"):
                           txtchck = new DropDownList();
                           break;
                       case ("Button"):
                           txtchck = new Button();
                           break;

                   }
                   if (txtchck != null)
                   {
                       Type controlType = txtchck.GetType();

                       PropertyInfo[] properties = controlType.GetProperties();

                       foreach (PropertyInfo controlProperty in properties)
                       {
                           stresult = stresult + controlProperty.Name+"<br />";
                       }

                   }
                   Response.Write(stresult);
                   Response.End();
               }
           }

       }
   }


I hope you know how to add Jquery reference to page

All the Best
 
Share this answer
 
Comments
lakshmichawala 10-Apr-12 8:51am    
Thanks murali and i will try and let u know
Muralikrishna8811 10-Apr-12 8:54am    
K

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900