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

iam using asp tree view .i have binded tree view from a dataset .I want to show a content of tree view in pop up in mouse over.I have some description for each node in the dataset how to show them in a pop in mouse over.

here is my code:

TVContent.Nodes.Clear();
            DataTable topics = dsSOW.Tables["Tableofcontents$"];
            drText = dsSOW.Tables["Tableofcontents" + "$"].Select("Mappingcode is NULL");

            if (drText.Length > 0)
            {
                foreach (DataRow drItem in drText)
                {
                    string ss = drItem.ItemArray[1].ToString();

                    string ss1 = drItem.ItemArray[0].ToString();
                    if (ss1 != string.Empty)
                    {
                        TreeNode node = new TreeNode(ss, ss1);
                          node.PopulateOnDemand = false;
                        TVContent.Nodes.Add(node);
                        
                        PopulateNode(node);

                    }

 

                }
            }

 


        protected void PopulateNode(TreeNode node1)
        {
            decimal order = Convert.ToDecimal(node1.Value);
            drText = dsSOW.Tables["Tableofcontents" + "$"].Select("Mappingcode='" + order + "'");

            if (drText.Length > 0)
            {
                foreach (DataRow drItem in drText)
                {

                    string ss = drItem.ItemArray[1].ToString();

                    string ss1 = drItem.ItemArray[0].ToString();


                    TreeNode node = new TreeNode(ss, ss1);
                  
                    node1.ChildNodes.Add(node);
                     snode = node.Value;
                    if (snode != string.Empty)
                    {

                        drText = dsSOW.Tables["Tableofcontents$"].Select("Mappingcode='" + snode + "'");
                        if (drText.Length > 0)
                        {
                            PopulateNode(node);
                        }
                    }
                }


            }

            TVContent.Attributes.Add("OnClick", "OnTreeClick(event)");
        }


Please help. !
Anusha
Posted

1 solution

You can use a css class for treenodes, Insert the content for the popup within a hidden div to each TreeNode during databound event from database and use jquery or javascript to display the divs content on hover.

Heres a sample.


XML
<asp:TreeView ID="LinksTreeView" runat="server" OnTreeNodeDataBound="Data_Bound" >            
            <NodeStyle CssClass="TreeItem" />
</asp:TreeView>

Please take note of the NodeStyle added. The CSS class 'TreeItem' gets added to anchor tags rendered for each node of treeview. We later use this class to add hover function to node using jquery.

Add a hidden div with required content to Node.text during databound event.
C#
void Data_Bound(Object sender, TreeNodeEventArgs e)
  {
    string Description = GetDescriptionByIdFromDB(Node.value);//Assuming u have ID of node from Database as Node.Value
    string Prefix = "<div style='display:none;' class='content'>" + Description + " </div>";  
    e.Node.Text = Prefix + e.Node.Text;

  }

The following script will alert the contents of the div added to Node.Text. Please customize it for your needs. The script searches inside the anchor tag hovered for a div with class 'content' and alerts its innerHTML.I have used jquery here because it was easier for me. The same thing can be done using javascript.

XML
<script type="text/javascript">


        $(document).ready(function() {
            $('a.TreeItem').hover(function() {
                alert($($(this).find('div.content')).html());
            });
        });

</script>


Hope this helps.
 
Share this answer
 

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