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
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.
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.
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.
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
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.
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
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.
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
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.
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.
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 BratanovProgress Telerik