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

AppointmentCreated event handler and Appointment.DataItem

17 Answers 426 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 08 Jun 2009, 11:14 AM
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

17 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 08 Jun 2009, 11:50 AM
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.
0
Peter
Telerik team
answered on 08 Jun 2009, 04:36 PM
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.
0
Andy
Top achievements
Rank 1
answered on 09 Jun 2009, 08:06 AM
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.

0
Peter
Telerik team
answered on 09 Jun 2009, 10:42 AM

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.
0
Kristian
Top achievements
Rank 1
answered on 28 Jun 2009, 10:15 AM
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
0
Content and Code
Top achievements
Rank 1
answered on 28 Feb 2012, 10:43 AM
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.
0
Content and Code
Top achievements
Rank 1
answered on 28 Feb 2012, 11:38 AM
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.
0
Andy
Top achievements
Rank 1
answered on 28 Feb 2012, 12:32 PM
I ended up with manually loading "dataItem" from the database by Appointment.ID in AppointmentCreated handler
0
Content and Code
Top achievements
Rank 1
answered on 28 Feb 2012, 12:36 PM
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. 
0
Peter
Telerik team
answered on 29 Feb 2012, 06:30 PM
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.
0
Content and Code
Top achievements
Rank 1
answered on 02 Mar 2012, 01:43 AM
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.

 

 




0
Peter
Telerik team
answered on 05 Mar 2012, 05:00 PM

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.
0
Matthew
Top achievements
Rank 1
answered on 23 Jul 2013, 08:19 PM
+1 I think this is the intuitive approach for developers. Guess I'll use a workaround.
0
Olivier
Top achievements
Rank 2
answered on 06 Jan 2015, 02:37 PM
+1 to Get a Entity From e.Appointment.DataItem , please !
0
Boyan Dimitrov
Telerik team
answered on 09 Jan 2015, 01:45 PM
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.

 
0
Slava
Top achievements
Rank 1
answered on 22 Dec 2017, 09:32 PM

It works fine when the calendar loads initially but after I would, for example, insert new appointment, and calendar would re-load after the insert it gives the "Object reference not set to an instance of an object." error within RadScheduler1_AppointmentDataBound void  on the line where (e.Appointment.DataItem as System.Data.DataRowView)["customColumn"] is used. Please advise? 

Thanks.

0
Marin Bratanov
Telerik team
answered on 25 Dec 2017, 01:19 PM

Hi,

I am attaching here an example that illustrates how you must save the custom fields directly in the data source and how you should check whether the data item has been initialized when the AppointmentDataBound fires. This should allow you to add null reference checks in your actual code to prevent the error.

I will also update the documentation on this type of data binding: https://github.com/telerik/ajax-docs/commit/af80222301f857fdbb7fcfc3de193c686faa4453.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Peter
Telerik team
Kristian
Top achievements
Rank 1
Content and Code
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Olivier
Top achievements
Rank 2
Boyan Dimitrov
Telerik team
Slava
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or