This is a migrated thread and some comments may be shown as answers.

RadGrid - How to Create Hierarchical Grid Using DataSet with Data Relation

3 Answers 350 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 19 May 2011, 05:53 PM

Once again, i find your documentation and demos so convoluted that I have given up trying to make any sense out it.

I am again trying to accomplish a very simple thing: make a hierarchical grid out of a simple, 2-table relational dataset.

All I wish to do is to create a simple parent-child hierachy in a RadGrid, using an ADO DataSet object containing 2 tables, with a DataRelation already added to the DataSet, which should be enough to establish a parent-child relationship.

Here is dummy code that creates the DataSet:

 

 

 

DataTable dt1 = new DataTable();

 

 

 

DataTable dt2 = new DataTable();

 

 

 

DataSet ds = new DataSet();

 

 

 

DataRow myRow;

 

 

dt1.Columns.Add(

"Period");

 

 

dt1.Columns.Add(

"Period_Name");

 

 

dt2.Columns.Add(

"Period");

 

 

dt2.Columns.Add(

"File_Name");

 

 

dt2.Columns.Add(

"Size");

 

 

 

 

myRow = dt1.NewRow();

 

myRow[

"Period"] = "60";

 

 

myRow[

"Period_Name"] = "April 2011";

 

 

dt1.Rows.Add(myRow);

 

myRow = dt1.NewRow();

 

myRow[

"Period"] = "59";

 

 

myRow[

"Period_Name"] = "March 2011";

 

 

dt1.Rows.Add(myRow);

 

myRow = dt1.NewRow();

 

myRow[

"Period"] = "58";

 

 

myRow[

"Period_Name"] = "February 2011";

 

 

dt1.Rows.Add(myRow);

 

myRow = dt1.NewRow();

 

myRow[

"Period"] = "57";

 

 

myRow[

"Period_Name"] = "January 2011";

 

 

dt1.Rows.Add(myRow);

 

myRow = dt2.NewRow();

 

myRow[

"Period"] = "60";

 

 

myRow[

"File_Name"] = "User_60_123456_1.pdf";

 

 

myRow[

"Size"] = "923324";

 

 

dt2.Rows.Add(myRow);

 

myRow = dt2.NewRow();

 

myRow[

"Period"] = "60";

 

 

myRow[

"File_Name"] = "User_60_123456_2.pdf";

 

 

myRow[

"Size"] = "433324";

 

 

dt2.Rows.Add(myRow);

 

myRow = dt2.NewRow();

 

myRow[

"Period"] = "60";

 

 

myRow[

"File_Name"] = "User_60_123456_3.pdf";

 

 

myRow[

"Size"] = "693324";

 

 

dt2.Rows.Add(myRow);

 

ds.Tables.Add(dt1);

 

ds.Tables.Add(dt2);

 

 

DataRelation dRel = new DataRelation("Period_to_PDF", ds.Tables[0].Columns["Period"],

 

 

ds.Tables[1].Columns[

"Period"]);

 

 

ds.Relations.Add(dRel);


Table #1 (dt1) is the parent DataTable, containing "periods"
Table #2 (dt2) is the child DataTable containing "files relating to a period"

Only Period #60 has child rows in dt2 in this example.

HOW DO I USE THIS DATASET TO CREATE A HIERARCHICAL RADGRID???????????????????? IS IT EVEN POSSIBLE?

I would think that simply binding it to a grid would do it, but apprently RadGrid is not very smart, since it does not recognize the DataRelation object in the DataSet    

(I yearn for the days of desktop grid control that handled all of that for you if you created a properly related dataset.




3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 May 2011, 07:55 AM
Hi Richard,

The following online example demonstrates RadGrid's capability to auto-generate a hierarchical representation of a mutli-table DataSet. Just set the AutogenerateHierarchy property of RadGrid to true and it will automatically generate the hierarchy based on the tables in the DataSet and their relations with one another.
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/autogeneratedhierarchy/defaultcs.aspx

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Gorka S.
Top achievements
Rank 1
answered on 19 Jun 2012, 08:57 AM
Hi,

I have a similar problem, but given solution does not solve it.

I want to use a DataSet with all the data for parent and detail grids, I want to use Client load, but I dont want to use AutoGenerateHierarchy because it doesnt allow me to specify detail grid columns declaratively and AllowPaging.

Could you give me any clue?

Thxs!
0
Pavlina
Telerik team
answered on 22 Jun 2012, 08:50 AM
Hello Gorka,

Basically there are two types of hierarchical grid you can use in your case:
- hierarchy with DetailTables definition
- auto-generated hierarchy

For the auto-generated hierarchy, you should only declare the grid and in its NeedDataSource assign a DataSet to the grid DataSource property. However in this case, all columns in each level will be autogenerated and to alter their properties you will need to handle the ColumnCreated event.

With the declarative DetailTables, you will need to use different SqlDataSource control for each level and define the ParentTableRelations. You can follow this demo and help topic. Additionally, one you have set the DataSourceID for the nested GridTableView, you should be able to add the desired columns using the grid Property Builder in VS Designer.

Kind regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Gorka S.
Top achievements
Rank 1
Share this question
or