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

Dynamic generation of Columns in RadGrid based on supplied definitions and Transpose data from database.

1 Answer 261 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 20 Apr 2011, 06:40 AM

 

Hi,

 

 

I have a requirement to generate the RadGrid Columns at runtime. Also the data supplied to the grid as the Data Source would be the result of a transpose.

 

            I have tables in my database that store the definitions for the structure of the grid. The tables define the number of columns, type of column to be used, header text, tooltip, group that the column belongs to, the auto generated id of the column, etc as shown in the attached image Post1.png.

 

 We might have additional add-ons to the set of properties of the table that would be stored later. For example an additional column called PARENT_COLUMN may be added to the above schema as shown in the attached image Post2.png.

 

 

 

. Based on the definition, columns would need to be constructed into a RadGrid whose tag is statically defined in the .aspx.

Example, the following would be placed on the aspx page.

<telerik:RadGrid ID=’grdDynamic’ runat=’server’ />

 

The grid has to support inline editing. Also the headers have to support grouping, i.e. rowspan and colspan.

The following structure is an example.

Name

Address

Add. Info

Phone Number

City

 

 

 

 



            The data which is added into the grid, displayed into the grid is transposed. I have a few tables with the same structure except for where the name of the primary representative columns in the grid changes.

For instance in the below displayed grid the CHECKLIST_ITEM_ID is the primary representative. In this case this might be autogenerated. We may also have a column , say ‘XYZ’, which might be a FOREIGN KEY to another table.

‘XYZ’ may not be autogenerated..

 

 The tables contain the reference column which points to the relative record to which the current item belongs to. For example, we have a table which stores all the grid structures defined as templates. TEMPLATE_ID represents each structure defined.Refer to image Post3.png

 

We have another table that contains the structure of the grid. In this table TEMPLATE_FIELD_ID is the primary key whereas TEMPLATE_ID is the foreign key that defines the TEMPLATE or grid to which these columns belong to.Refer to image Post4.png

 

The data for this particular template is stored in a third table which stores the TEMPLATE_FIELD_ID, i.e. the ID of the column in the database, the ROW_NUM , which represents the row number of the item in the table, the Item, which stores the value entered by the user in the cell represented by the ROW_NUM, TEMPLATE_FIELD_ID,CHECKLIST_ID.

 

The CHECKLIST_ID represents the checklist that is created using the template as start.

Multiple checklists can be created using one TEMPLATE.Refer to image Post5.png

 

 

 

 

 


The code should handle the transpose of the data to get the data in the required format.

Also, it should create the grid at runtime.

 

I would like the programmer to have minimum effort to get the work done as it is to be done in multiple places.

Also, it would be better if you provided us with a custom Grid Control that would take very minimum parameters to get the work done. The code should also be easy to maintain as in the long run we are expecting to have more changes to the structure. Also it should provide flexibility to provide join querys . On the insert/update/delete command it should either perform the required actions automatically or provide the updated values in the untransposed format in a simple manner so that the developer can perform the required operations.

 

Name

Address

Add. Info

Phone Number

City

John

Avenue Park

1800-160-144

Galaba Galaba

 

 

 

 


Thanks in Advance.

 

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 25 Apr 2011, 04:30 PM
Hello David,

To define the structure of a RadGrid control that is declared in the ASPX page, use the Page_Load event handler. Columns and detail table should be added to the corresponding collection first, before the values for their properties are set. This is important because no ViewState is managed for the object before it has been added to the corresponding collection. More information is available here:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

Regarding the inline editing, please refer to this online example:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultcs.aspx

The following code library demonstrates how to span any given cell over a number of rows/columns, with autogenerated columns in the control.
http://www.telerik.com/community/code-library/aspnet-ajax/grid/span-cells-in-grid-over-multiple-positions.aspx

Telerik RadGrid supports dependant grids out-of-the-box in a similar means as the MS GridView. The main points for attaining this behavior are presented in the link below:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx

I hope this information gets you started properly.

Greetings,
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.

Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or