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

Creating columns dynamically fails.

6 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Izik
Top achievements
Rank 1
Izik asked on 09 Dec 2010, 04:52 PM
Hello,
I tried to create the columns on the radgrid dynamically on Page_load (I can't create them on page_init)
I followed the instructions on your site but I keep getting the following error after each postback once the grid is created:

[GridException: Cannot find a column with UniqueName 'alert_id']
   Telerik.Web.UI.GridTableView.GetColumn(String columnUniqueName) +102
   Telerik.Web.UI.RadGrid.LoadClientState(Dictionary`2 clientState) +5156
   Telerik.Web.UI.RadCompositeDataBoundControl.LoadPostData(String postDataKey, NameValueCollection postCollection) +109
   Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +690
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743

I added the bound-columns to the mastertable before I set their properties.

The grid is created once, but each postback throws this error.
The error occures even before "Page_Load" happens.

My main goal is to add a button to the header which will open a custom context menu (so I can't use auto-generate-columns) and still have all the functionalities of group-by/sort/reorder etc. also, the grid's columns should be created dynamically since the datasource is set during run-time and I don't know what are its columns at design time - The grid is inside a RadTabStrip and each tab-click sets a different data source into the grid

6 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Dec 2010, 01:34 PM
Hi Izik,

Do you have template columns for your grid? If so, you do need to create the whole grid in the Page_Init event:
http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

Regards,
Tsvetoslav
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
Izik
Top achievements
Rank 1
answered on 13 Dec 2010, 02:08 PM
No, I Used BoundColumn, and on the "ColumnCreated"  event I added a button to the header.
I didn't use the template columns because I can't create the columns on page_init (I don't have the datasource yet).

Any alternative way would be okay!
Again, the goal is to simply add a button to the grid's header, and make it open a custom RadMenu, while I only get the datasource at page_load.

Nothing worked...

If I use "autoGenerateColumns" - I can't reach the header to add a button (or add a script to open the RadMenu).
If I try to create them programatically (at page load) I can't do anything - every postback causes the error : 
'Cannot find a column with UniqueName  <first_column_name>' or no records are shown...

Thanks for any help,

Izik
0
Accepted
Tsvetoslav
Telerik team
answered on 16 Dec 2010, 12:37 PM
Hi Izik,

Attached is a small sample.

Hope it helps.

Best wishes,
Tsvetoslav
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
Izik
Top achievements
Rank 1
answered on 23 Dec 2010, 02:49 PM
Thank you, it helped me!
0
Asela Goonatilleke
Top achievements
Rank 1
answered on 23 Apr 2014, 01:40 AM
Hi,
I too experience this issue intermittently. The grid loads most of the time without any issue. However, at times I see this on the error log. We also create and load the columns dynamically however from your sample I noticed there is one difference. We use OnInit event for grid initialization instead of Page_Init as said. Is it correct to use OnInit function or should we change to
Page_Init. I cannot simulate this at our end but it happens on the production environment.

Any help would be appreciated.
 
Thanks,
Asela

0
Pavlina
Telerik team
answered on 25 Apr 2014, 03:47 PM
Hi Asela,

Did you try to create the grid on Page_Init instead of  using OnInit event handler? Does this make any difference? If not I will ask you to share the problematic code with us, so we can check what might be the reason for the issue you are facing?

Regards,
Pavlina
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
Izik
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Izik
Top achievements
Rank 1
Asela Goonatilleke
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or