Monday, 1 December 2014

Tree View in asp.net

//Tree view show,select and show selected values

 <div>
        <asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="Leaf" >
            <Nodes>
                <asp:TreeNode Text="Main" Value="Main">
                    <asp:TreeNode Text="child" Value="child"></asp:TreeNode>
                    <asp:TreeNode Text="child2" Value="child2"></asp:TreeNode>
                    <asp:TreeNode Text="child3" Value="child3"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="Main2" Value="Main2">
                    <asp:TreeNode Text="child4" Value="child4"></asp:TreeNode>
                    <asp:TreeNode Text="child5" Value="child5"></asp:TreeNode>
                </asp:TreeNode>
            </Nodes>
           
        </asp:TreeView>
        <asp:Button ID="Button1" runat="server" Text="submit" OnClick="Button1_Click" />
    </div>
//Show selected values
 protected void Button1_Click(object sender, EventArgs e)
    {
        foreach( TreeNode t1 in this.TreeView1.CheckedNodes )
        {
            Response.Write(t1.Text);
        }
    }

No comments:

Post a Comment