AppointmentCreated event handler and Appointment.DataItem

16 posts, 0 answers
  1. Andy
    Andy avatar
    54 posts
    Member since:
    Jun 2009

    Posted 08 Jun 2009 Link to this post

    Hi guys!
    I'm a bit stuck with binding data to the Scheduler control. For example, in the AppointmentTemplate I have a label and I need to fill it's Text property with some data, based on the bound DataItem. If I use AppointmentCreated event handler, I can access the label fine using e.Container , but e.Appointment.DataItem is always NULL. If I use AppointmentDataBound event handler, DataItem does contain the object I need, but I can't figure out how to access the label.

    Thanx a lot in advance!
    Regards,
    Andy
  2. Andy
    Andy avatar
    54 posts
    Member since:
    Jun 2009

    Posted 08 Jun 2009 Link to this post

    The only workaround I found so far is to get data bound object from the database using Appointment.ID in AppointmentCreated event handler, but it's surely an overhead.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 Jun 2009 Link to this post

    Hello Andy,

    I wonder whether you can use custom attributes. For example:
     <telerik:RadScheduler ID="RadScheduler1" 
         runat="server"   
         CustomAttributeNames="Annotations">  
            <AppointmentTemplate> 
                <%#Eval("Annotations") %> 
            </AppointmentTemplate> 
        </telerik:RadScheduler> 

    If that's not plausible, please, explain what exactly you need to achieve and we will help you find a solution.

    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Andy
    Andy avatar
    54 posts
    Member since:
    Jun 2009

    Posted 09 Jun 2009 Link to this post

    Thanks a lot for the reply Peter!
    Well, yes, I guess custom attributes can be used.. However I think it would be more convinient if there was a way to access bound data object directly.

    Best Regards,
    Andy.

  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 09 Jun 2009 Link to this post


    We will consider your suggestion. Thanks.


    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Kristian
    Kristian avatar
    7 posts
    Member since:
    Dec 2008

    Posted 28 Jun 2009 Link to this post

    Hi there,
    I would also like to have a way to access the original DataItem.
    Most databound controls have support for this, and CustomAttributes are not a very nice workaround, since it requires all properties to be converted into strings.... so fx Enums are of no use.

    Regards,

    Kristian
  8. Content and Code
    Content and Code avatar
    26 posts
    Member since:
    Oct 2004

    Posted 28 Feb 2012 Link to this post

    Any luck with this? I need this too i.e. I need to get a control from the appointmenttemplate and based on the appointment id do something.
  9. Content and Code
    Content and Code avatar
    26 posts
    Member since:
    Oct 2004

    Posted 28 Feb 2012 Link to this post

    I urgently need some help with this, the issue is I need to use some if statements and based on that control how the template looks. I havent been able to find a way because in appointment_databound i cant get the controls whereas in appointment_created i cant get the dataitem.
  10. Andy
    Andy avatar
    54 posts
    Member since:
    Jun 2009

    Posted 28 Feb 2012 Link to this post

    I ended up with manually loading "dataItem" from the database by Appointment.ID in AppointmentCreated handler
  11. Content and Code
    Content and Code avatar
    26 posts
    Member since:
    Oct 2004

    Posted 28 Feb 2012 Link to this post

    Thanks Andy.

    I cant use that approach as it would have a massive impact on performance in my scenario.

    Can one of the telerik guys please advise of another way? The appointment_created event fires after the appointment_databound event, I cannot understand why the dataitem couldnt have been made available in appointment_created. 
  12. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 29 Feb 2012 Link to this post

    Hello,

    There isn't any other way I can think of that could do the trick for your requirement. I understand your point that the DataItem could have been exposed in AppointmentCreated and that is why I will forward your suggestion to our development team to review it.

    All the best,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  13. Content and Code
    Content and Code avatar
    26 posts
    Member since:
    Oct 2004

    Posted 01 Mar 2012 Link to this post

    Hi Peter,

    I will be grateful if you guys can seriously consider this suggestion which was originally raised by Andy almost 3 years ago. I really think this is a real short short coming of an otherwise very excellant Scheduler control.

    By the way, I did find a solution to my problem.

    In the Scheduler_AppointmentDataBound(object sender, SchedulerEventArgs e) event (where I have the data item) I get the appointment object and set some attributes:

    MyCustomEntity item = (
    MyCustomEntity )e.Appointment.DataItem;

    e.Appointment.Attributes["EmployeeId"] = item.EmployeeId;
    .....

    Then in the Scheduler_AppointmentCreated event I can access these attributes:

    string employeeId = e.Appointment.Attributes["EmployeeId"];

    Basically, I am myself passing the required data from databound event to the AppointmentCreatedEvent. Its not perfect but a work around.

     

     




  14. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 05 Mar 2012 Link to this post


    Thank you for sharing your workaround.

    I have just got an update from our development team on this case. They said that after ApointmentDataBound, the DataItem objects are destroyed. We could save them somehow and pass them to AppointmentCreated, but that would create overhead. Nevertheless, we will do more research and consider your suggestion. If we can find an elegant way to implement it, we will do it.


    All the best,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  15. Matthew
    Matthew avatar
    51 posts
    Member since:
    Oct 2012

    Posted 23 Jul 2013 Link to this post

    +1 I think this is the intuitive approach for developers. Guess I'll use a workaround.
  16. Olivier
    Olivier avatar
    146 posts
    Member since:
    Nov 2010

    Posted 06 Jan 2015 Link to this post

    +1 to Get a Entity From e.Appointment.DataItem , please !
  17. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 09 Jan 2015 Link to this post

    Hello,

    In order to avoid any confusion I would like to clarify that if we do not destroy the DataItem object after the AppointmentDataBound event this will cause a serious load and the performance will be drastically reduced.

    An easy and convenient solution in order to keep some values from the DataItem after the AppointmentDataBound event is to add an attribute to the appointment object.
    //code behind
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
        {
            string customAttribute = (e.Appointment.DataItem as System.Data.DataRowView)["customColumn"].ToString();
            e.Appointment.Attributes.Add("customAttr", customAttribute);
        }



    Regards,
    Boyan Dimitrov
    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017