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

RadGrid - setting EventHandler programmatically does not work

4 Answers 312 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Serge
Top achievements
Rank 1
Serge asked on 26 Aug 2017, 07:12 PM

I order to test the hierarchical RadGrid I created a new Telerik-.Net Web Application Project in ym Visual Studio 20167 express and copied thesourcesof the demo from here:

http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarative-relations/defaultcs.aspx

The declarative Project works fine.

Since I need a 100% "code behind" solution I then commented the aspx code for the RadGrid and moved the properties step by step in the cs-file into the Page_Load handler. It worked fine until I also moved the the Event handler declarations for "OnDetailTableDataBind" and "OnNeedDataSource" from the aspx-file to the cs-file like here:

RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(needDataSource);
RadGrid1.DetailTableDataBind += new GridDetailTableDataBindEventHandler(detailTableDataBind);

To my surprise the event handlers are not triggered any more when I start the application.

Are there any issues with the event handlers? What could be the reason? 

Many thanks!

 

4 Answers, 1 is accepted

Sort by
0
Serge
Top achievements
Rank 1
answered on 26 Aug 2017, 07:24 PM

I just tried and moved the declaration from the Page_Load handler to the Page_init handler and now it works, cause the page_init is called every time I klik on an new page or on a child row: 

                 //Event handlers
                RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(needDataSource);
                RadGrid1.DetailTableDataBind += new GridDetailTableDataBindEventHandler(detailTableDataBind);

 

I also read this link:

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically

 

0
Serge
Top achievements
Rank 1
answered on 27 Aug 2017, 08:45 AM
However the question still remains - when I initialise the handlers in the Page_Load method, why are they not working?
0
Serge
Top achievements
Rank 1
answered on 27 Aug 2017, 10:06 AM

I followed the example in

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically

However the part :

GridRelationFields relationFields = new GridRelationFields(); relationFields.MasterKeyField = "CustomerID"; relationFields.DetailKeyField = "CustomerID"; tableViewOrders.ParentTableRelation.Add(relationFields);

does not work. Without this part my example works fine.... Any idea?

0
Eyup
Telerik team
answered on 31 Aug 2017, 01:07 PM
Hi Serge,

This is because the Page_Load event is raised too late in the page life cycle:
https://msdn.microsoft.com/en-us/library/ms178472.aspx

We highly recommend that you use the Page_Init instead, as demonstrated in this section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-a-hierarchical-grid-programmatically

As for the relation settings, you do not them when binding the grid programmatically using NeedDataSource and DetailTableDataBind event handlers:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-a-hierarchical-grid-programmatically

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Serge
Top achievements
Rank 1
Answers by
Serge
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or