How to Expand and Collapse asp TreeView Using Button

Advertisement
I want to Expand and Collapse Asp TreeView control using button, In page load i expand all nodes. button will show "hide". While clicking hide it will show "Show" all nodes will Collapse.

In Ascx page:

        <asp:Button runat="server" ID="btnhide" OnClick="btnhide_onclick" Text="Hide" />
        <asp:TreeView ID="TreeViewID" runat="server">                            
        </asp:TreeView>
    
In Pageload:

 TreeViewID.ExpandAll();

Button OnClick

protected void btnhide_onclick(object sender, EventArgs e)
        {
            if (btnhide.Text == "Hide")
            {
                TreeViewID.CollapseAll();
                btnhide.Text = "Show";               
            }
            else
            {
                if(btnhide.Text == "Show all")
                {
                    TreeViewID.ExpandAll();
                    btnhide.Text = "Hide all";
                }
            }           


        }
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment