Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Representing hierarchical data using a DataGrid/GridView control

I do not have access to third party components on this project. I think I only have access to the built-in DataGrid and GridView controls.

Is there a good example for representing hierarchical data (inside a grid - Master /Details) in a built-in ASP.NET server control?

I am looking for an expand/collapse tree structure kind of implementation.

like image 378
kalls Avatar asked Jul 19 '26 21:07

kalls


1 Answers

You're after the TreeView Server Control.

This is built into ASP.NET (System.Web.UI.WebControls).

Code sample from the Microsoft Reference (for static content):

<asp:TreeView ID="MyTreeView" Runat="server">
  <Nodes>
    <asp:TreeNode Value="Child1" Expanded="True" Text="1">
      <asp:TreeNode Value="Grandchild1" Text="A" />
      <asp:TreeNode Value="Grandchild2" Text="B" />
    </asp:TreeNode>
    <asp:TreeNode Value="Child2" Text="2" />
    <asp:TreeNode Value="Child3" Expanded="True" Text="3">
      <asp:TreeNode Value="Grandchild1" Text="A" />
    </asp:TreeNode>
  </Nodes>
</asp:TreeView>

You can also build a Treeview Dynamically.

There are good samples at MSDN for this.

like image 158
Brian Webster Avatar answered Jul 22 '26 11:07

Brian Webster