Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 4-Oct-12 18:35pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 

<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.
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.
 
<script type="text/javascript">
 

        $(document).ready(function() {
            $('a.TreeItem').hover(function() {
                alert($($(this).find('div.content')).html());
            });
        });
 
</script>
 
Hope this helps.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 530
1 Sergey Alexandrovich Kryukov 330
2 BillWoodruff 299
3 PIEBALDconsult 230
4 CPallini 220
0 Sergey Alexandrovich Kryukov 10,615
1 Maciej Los 5,354
2 OriginalGriff 5,254
3 CPallini 3,719
4 BillWoodruff 3,476


Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100