RadGrid - setting EventHandler programmatically does not work

5 posts, 0 answers
  1. Serge
    Serge avatar
    5 posts
    Member since:
    Aug 2017

    Posted 26 Aug 2017 Link to this post

    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!

     

  2. Serge
    Serge avatar
    5 posts
    Member since:
    Aug 2017

    Posted 26 Aug 2017 in reply to Serge Link to this post

    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

     

  3. Serge
    Serge avatar
    5 posts
    Member since:
    Aug 2017

    Posted 27 Aug 2017 in reply to Serge Link to this post

    However the question still remains - when I initialise the handlers in the Page_Load method, why are they not working?
  4. Serge
    Serge avatar
    5 posts
    Member since:
    Aug 2017

    Posted 27 Aug 2017 in reply to Serge Link to this post

    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?

  5. Eyup
    Admin
    Eyup avatar
    3824 posts

    Posted 31 Aug 2017 Link to this post

    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.
Back to Top