FAQ: Display (Expand/Collapse) Hierarchical in ASP.NET DataGrid

I always see the question of “How to display hierarchical data in a DataGrid” in different Forums, Newsgroup, List Servers...etc etc. Therefore, a lot of articles were written in this topic, some of them use WITH ROLLUP keyword in TSQL, some of them use Nested DataGrid, some of them like injecting data into a Table/DataGrid control during ItemDataBound... etc etc, there're really tens of different approach to do the same result. Today, a new columnist join ASPAlliance, his name is Denis Bauer and his first article is exactly talking in this subject.

He wrote a Custom Control named “
HierarGrid“ and just published an article about how to use it. This control is a DataGrid-like control and capable of displaying parent-child relationship / data. Moreover, it will generate a Expand/Collapse (Javascript) and toggle the visibibility of the child data per parent item:

HierarGrid sample

(It's nice and save a lot of time for page developers who want to bind master-detailed datagrid AND write the Javascript)

It's not the first time for me to hear his name - Denis, he is a MS Germany employee and post quite a lot of messages to the ASP.NET Forum, he wrote an article about how to (re)create dynamic control across PostBack (DynamicControl) in the very beginning, he also create a ASP.NET Version Switcher 1.0 which enable us to switch between v1.0 and v1.1 in a simple interface. They're all cool.

Published Sunday, August 17, 2003 5:59 PM by Colt
Filed under:

Comments

# re: FAQ: Display (Expand/Collapse) Hierarchical in ASP.NET DataGrid

Seems to be a great control , excellent effort.

Works fine with the sample application proveded - where data source is read from an xml file.

I m using SQL db(northwind ) and tried it for tabels [Parent as] 'customer' and [Child as] 'order' (relation of field 'customerid')

In the child child template file i have a simple asp.net datagrid control and to bind this child contorl i use the code as said, but unfortunately get following error when typecasting the (..dgi..)datagriditem to data set:

"Specified cast is not valid."
i m pasting the code i m using to bind the datagrid in the child template

Dim dgi As DataGridItem = CType(Me.BindingContainer, DataGridItem)
Dim ds As DataSet = CType(dgi.DataItem, DataSet)
dg.DataSource = ds
dg.DataMember = "orders"
dg.DataBind()

Friday, February 6, 2004 2:43 PM by rohan gandhi

# re: FAQ: Display (Expand/Collapse) Hierarchical in ASP.NET DataGrid

basically the main problen i m facing is to bind the datagrid in a child template.... Ctype ... just doesnt work as:

the dataitem retrieved :
Dim dgi As DataGridItem = CType(Me.BindingContainer, DataGridItem)

contains only a datarowview instead a dataset... therefore converting to the dataset type gives error "Specified cast is not valid."

Friday, February 6, 2004 2:49 PM by vineet rawat

# re: FAQ: Display (Expand/Collapse) Hierarchical in ASP.NET DataGrid

I get the same error!

Friday, July 16, 2004 10:52 AM by Joe

# re: FAQ: Display (Expand/Collapse) Hierarchical in ASP.NET DataGrid

Try the datagrid from www.progtalk.com!

You can expand and collapse through client side.

Friday, October 19, 2007 12:47 PM by AProgrammer