Hi All,

I've built a treeview control, programmatically adding the nodes in
the code behind, all is fantastic, however my Parent Nodes are showing
when i click the parent Nodes go to corresponding category url and
display the corresponding child Nodes

please help this concern
    aspx File

<asp:TreeView runat="server" CssClass="w-text"
                ID="TreeView1" ExpandDepth="0"
ExpandImageUrl="Images/spacer.gif"
                CollapseImageUrl="Images/spacer.gif"
                SelectedNodeStyle-BorderStyle="None"
                SelectedNodeStyle-BorderWidth="1px"
                SelectedNodeStyle-Font-Bold="true"
                NodeStyle-Font-Size="XX-Small"
                NodeStyle-HorizontalPadding="2px"
                OnTreeNodePopulate="TreeView1_TreeNodePopulate"
                onselectednodechanged="TreeView1_SelectedNodeChanged"
 
ontreenodecheckchanged="TreeView1_TreeNodeCheckChanged"
OnUnload="TreeView1_Unload">
                <ParentNodeStyle Font-Bold="False" />
                <HoverNodeStyle Font-Underline="True" />
                <SelectedNodeStyle BorderWidth="1px"
BorderStyle="Dashed" ForeColor="White" Font-Bold="True" ></
SelectedNodeStyle>
                    <RootNodeStyle ImageUrl="Images/bullet_36.jpg" />
                <NodeStyle HorizontalPadding="2px" ImageUrl="Images/
bullet_36.jpg"  Font-Size="10pt" NodeSpacing="1px" ForeColor="White"
VerticalPadding="2px" ></NodeStyle>
                </asp:TreeView>
    cs file
    private void PopulateRootLevel()
    {
        DataTable dt = new LPBusiness.LPUserFunction
().GetParentCategory();
        PopulateNodes(dt, TreeView1.Nodes);
    }

    private void PopulateSubLevel(int parentid, TreeNode parentNode)
    {
        //Response.Write("parentNode=" + parentNode);
        DataTable dt = new LPBusiness.LPUserFunction
().GetParentCategory(parentid);
        PopulateNodes(dt, parentNode.ChildNodes);
    }


    protected void TreeView1_TreeNodePopulate(object sender,
TreeNodeEventArgs e)
    {
        PopulateSubLevel(Int32.Parse(e.Node.Value), e.Node);
    }

    private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
    {
        foreach (DataRow dr in dt.Rows)
        {
            TreeNode tn = new TreeNode();
            tn.Text = dr["Name"].ToString();
            tn.Value = dr["CatId"].ToString();
            nodes.Add(tn);
            tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0);
        }
    }
    protected void TreeView1_SelectedNodeChanged(object sender,
EventArgs e)
    {
        //TreeView1.TreeNode node = null;
        //TreeView1.TreeNode parentNode = null;
        if (Request.QueryString["Lg"] != null)
        {
            Int32 CatId = Int32.Parse
(TreeView1.SelectedNode.Value.ToString());

            PopulateSubLevel(CatId, parentNode.ChildNodes);
            Response.Redirect("index.aspx?CId=" +
TreeView1.SelectedNode.Value + "&Lg=" + Request.QueryString["Lg"]);
        }
        else
        {
            Int32 CatId = Int32.Parse
(TreeView1.SelectedNode.Value.ToString());
            PopulateSubLevel(CatId, parentNode.ChildNodes);
            Response.Redirect("index.aspx?CId=" +
TreeView1.SelectedNode.Value + "");
        }
    }

Regards
Sambath

Reply via email to