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

RadGrid programmatically

3 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vadim
Top achievements
Rank 1
vadim asked on 25 Sep 2014, 06:26 PM
Hello,

I need an argent help with the following requirement:

on each Treeview node click I need to load Grid
with different columns, headers and data .



I create a grid on Click event of the TreeView,
but the generated Grid disappears on PostBack 

 

protected void CreateGrid()

        {

           
RadGrid DataGrid = new RadGrid();

           
DataGrid.ID = "DataGrid";           

           
DataGrid.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;

           
DataGrid.enablea

            DataGrid.AutoGenerateColumns
= true;

           
DataGrid.MasterTableView.AutoGenerateColumns = false;

           
DataGrid.MasterTableView.ShowHeadersWhenNoRecords = true;



           
GetGridHeader(table_name, DataGrid);

           
DataGrid.DataSource = GetData(table_name);

           
DataGrid.DataBind();

           
PlaceHolder1.Controls.Add(DataGrid);



}


Please advise what is the best way to do it, and
what is the problem with my approach.

Thank you,
Vadim


















































3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 30 Sep 2014, 11:11 AM
Hi Vadim,

When creating a RadGrid with dynamic structure programmatically you need to use the Page_Init event. In the handler you could check what is the selected value in a TreeView or other control and create the grid with appropriate structure.

Check out the following article that explains the approach in more detail. There is also sample code you could use as a starting point:


Regards,
Viktor Tachev
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
vadim
Top achievements
Rank 1
answered on 01 Oct 2014, 02:57 PM
Hello Viktor,
Thank you for the link it helped me a lot, but already a second day I can't figure out how to get TreeView Node text using Request.Form as shown in your example. I will really appreciate your help. Is there any other way to create Grid  programmatically not in Page_Init event ?

Thank you,Vadim
0
Viktor Tachev
Telerik team
answered on 06 Oct 2014, 11:43 AM
Hi Vadim,

I have prepared a sample project that illustrates the approach you can use in order to create the RadGrid dynamically based on the selected node in a RadTreeView. You will find the sample attached. Give it a try and let me know how it works for you.

Regards,
Viktor Tachev
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
vadim
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
vadim
Top achievements
Rank 1
Share this question
or