Thursday 8 January 2015

Treeview Dynamically populate and remove Hyperlinks from nodes using asp.net c#

//Html

<asp:TreeView ID="TreeView1" ShowCheckBoxes="All" runat="server" NodeIndent="15"   >
                            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                            <NodeStyle Font-Names="Arial" Font-Size="9pt" ForeColor="Black" HorizontalPadding="1px"
                                NodeSpacing="0px" VerticalPadding="1px" ></NodeStyle>
                            <ParentNodeStyle Font-Bold="False" />

                        </asp:TreeView>


//Remove Hyperlinks
System.Web.UI.WebControls.TreeView RemoveHyperLinks(System.Web.UI.WebControls.TreeView treeView, TreeNodeCollection treeNodes)
    {
        foreach (TreeNode node in treeNodes)
        {
            node.SelectAction = TreeNodeSelectAction.None;//here the link is removed
            if (node.ChildNodes != null && node.ChildNodes.Count > 0)
            {
                treeView = RemoveHyperLinks(treeView, node.ChildNodes);
            }
        }
        return treeView;
    }


//Populate Treeview Dynamically

    private void PopulateTreeView(DataTable dtParent, string parentId, TreeNode treeNode)
    {
        foreach (DataRow row in dtParent.Rows)
        {
            if (parentId == "")
            {
                TreeNode child = new TreeNode
                {
                    Text = row["InterventionType"].ToString(),
                    Value = row["InterventionID"].ToString()
                };
                TreeView1.Nodes.Add(child);
                DataTable dtChild = this.GetData("");
                PopulateTreeView(dtChild, Convert.ToString(child.Value), child);
            }
            else
            {
                TreeNode child1 = new TreeNode
                {
                    Text = row["ActivityName"].ToString(),
                    Value = row["ActivityID"].ToString()
                };
                treeNode.ChildNodes.Add(child1);
            }
            TreeView1.CollapseAll();
            RemoveHyperLinks(TreeView1, TreeView1.Nodes);
        }
    }


No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...