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

Dynamic Hierarchical Grids with Edit capabilities On Demand

3 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ramesh
Top achievements
Rank 1
Ramesh asked on 20 Aug 2014, 02:57 PM
Hi,
Can someone guide me on how to generate hierarchical grids dynamically from code behind based on certain business rules that will reside in separate tabs of a RadTabStrip. The grids should be fully editable and ajaxified. The grids will bind to different data sources based on the rules.

Thanks.

​ for (int i = 0; i < 5; i++)
{

RadGrid RadGrid1 = new RadGrid();
if (i == 0)
RadGrid1.DataSource = crList0;
else RadGrid1.DataSource = crList1;
RadGrid1.DataBind();
RadGrid1.MasterTableView.DataKeyNames = new string[] { "FriendlyKey" };
RadGrid1.AllowPaging = true;
RadGrid1.AutoGenerateColumns = false;
RadGrid1.AutoGenerateEditColumn = true;
RadGrid1.Skin = "Metro";
RadGrid1.AllowPaging = false;
RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);
RadGrid1.RenderMode = RenderMode.Lightweight;

GridBoundColumn boundColumn1;
boundColumn1 = new GridBoundColumn();
boundColumn1.DataField = "FriendlyKey";
boundColumn1.HeaderText = "FriendlyKey";
boundColumn1.UniqueName = "FriendlyKey";
RadGrid1.MasterTableView.Columns.Add(boundColumn1);
GridBoundColumn boundColumn2;
boundColumn2 = new GridBoundColumn();
boundColumn2.DataField = "ApplicationName";
boundColumn2.HeaderText = "Application Name";
boundColumn2.UniqueName = "ApplicationName";
RadGrid1.MasterTableView.Columns.Add(boundColumn2);

//PlaceHolder1.Controls.Add(RadGrid1);

RadTab tab = new RadTab();
tab.Text = i.ToString();
tab.PageViewID = i.ToString();
myStrip.Tabs.Add(tab);
RadPageView pageView = new RadPageView();
pageView.ID = i.ToString();
RadMultiPage1.PageViews.Add(pageView);
RadMultiPage1.PageViews[i].Controls.Add(RadGrid1);

}

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 22 Aug 2014, 08:19 AM
Hello Ramesh,

To implement the described scenario, you will need to create the grid programmatically during Page_Init:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22

And follow the steps provided in the following article:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

If you need to create column templates, here is how:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section4

In case you will create an entire FormTemplate programmatically and not only Item and EditItemTemplates, you can check the attached web site sample.

Hope this helps.


Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ramesh
Top achievements
Rank 1
answered on 26 Aug 2014, 04:06 PM
Thanks - But, this seems to work for a single grid created dynamically at runtime. What about the case where there are multiple grids that need to be created during runtime. How do I get a handle to the right grid to make updates based on any edits performed by the user?
0
Eyup
Telerik team
answered on 29 Aug 2014, 06:56 AM
Hello Ramesh,

The instructions also apply for creating multiple or hierarchical grids:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section3

Can you elaborate on your specific scenario and what exactly you have difficulties achieving?

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ramesh
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ramesh
Top achievements
Rank 1
Share this question
or