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

Appreciate help to get grid working with hierarchical data

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 06 Dec 2010, 03:44 PM
Hi. I am just starting to try to use the grid control. What I am trying to do encompasses several different things and any help would be appreciated. Once I've done it once I will then know how to do it all in the future. Thanks

The page that I have needs a single grid that is actually derived from 3 fairly simple tables:

Table 1
RsId - unique primary key auto generated in the database
RType - int (will always be 0 for this page)
Description - varchar

Table 2
Cid- unique primary key auto generated in the database
RsId - linked to Table1:RsId  (actually is a 1:1 relationship but database assumes 1 to many)
CType - int
CMax - int

Table 3
LRid - unique primary key auto generated in the database
RsId - linked to table1:RsId
LType - char()
LText - nchar()

There are reasons why table 1 and table 2 are not merged into a single table. Questions:
1. What is the easiest way to build a hierarchical grid with two levels of hierarchy: first effectively representing a join of table1 and table2 (since they effectively have a 1:1 relationship) and the detailsview having related Table 3 records
2. When I "Add new record" I want to create a table1 record so I can have an insert query in my sqldatasource. If I don't have RType in my grid how do I define the sql command such that RType is always set to int 0.
3. When I "Add new record" in the master view is there an event that I can use to create the table2 record that will match the new table1 record or create the new records in both tables.
4. In table2 CType has a set of predefined potential values. How do I define CType as a drop down where the grid control's definition contains the int value (that will be the value stored in the database) and the text to display in the drop down?

Thanks

Update:
Finding my way on [1] but several things are far from obvious. It's not clear what the best way is to create the hierarchical structure but I have managed to do it (maybe not the best way - who knows). However, I have had to create 2 sqldatasources (one for the masterview and one for the details). I couldn't see an automatic way to get the wizard to create the second datasource so I created it manually and then edited the code for the grid control to define the data source under

<

 

DetailTables>

 

 

<telerik:GridTableView runat="server" AllowAutomaticDeletes="True" DataSourceID="SqlDataSource2" Width="100%" AllowFilteringByColumn="False"

 

 

AutoGenerateColumns="True" CommandItemDisplay="Top">

 

However, I have had to specify autogeneratecolumns because its not obvious to me at the moment how I define the columns for the details view using the object property builder for the grid. This is a problem because I don't want all of the columns to be visible. How do you create and define the details view?

Found how to do [2]
I think I can do [3] but haven't implemented it yet
Looking for solution to [4]
Trying to work out how to define the Insert query for the details view (ie for Table3)

1 Answer, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 10 Dec 2010, 11:11 AM
Hi Paul,

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.

Regarding [4]: You can try using the GridDropwDownColumn.

And for the Insert query issue: Just configure the InsertCommand in the SqlDataSource control and use Parameter or SessionParameter for the query parameters. The grid should automatically fill the values of these parameters once the Insert button is clicked. Note that you should set the AllowAutomaticInserts property of the grid to true and you should add the primary key fields of the data table to the DataKeyNames collection of the corresponding GridTableView. You can use this demo as a reference.

Regards,
Iana
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.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or