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

Get custom attributes from appointment item

6 Answers 537 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 20 Sep 2010, 09:16 PM

I've got an aspx page, and in the code behind, I'm building a list of Telerik.Web.UI.Appointment objects, and setting the datasource of the RadScheduler to that list.

For each appointment object I'm adding several attributes to it. Things like CusomerID.

appt.Attributes.Add("CustomerID", 23);

I need to get at this information client side. From the documentation, it appears to me that this should work, but it does not.

var appt = eventArgs.get_appointment();
var list = appt.get_attributes();
var attr = list.getAttribute('CustomerID');

When I run this, attr is always undefined.

So, what is my problem? Am I not adding the attributes in the correct way on the server side, or is something messed up with my client side call?

6 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 23 Sep 2010, 02:57 PM
Hello Matt,

In which event handler you are trying to get the custom attributes for the appointment? I tried the same code in OnClientAppointmentClick event and it works OK. I see nothing wrong with the code.

Could you please send me the full code so I can inspect it and help you?

Thank you!

Kind regards,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Matt
Top achievements
Rank 1
answered on 23 Sep 2010, 08:34 PM
I've dropped in a complete sample that displays the problem.  The Format Code Block tool keeps erroring out on me.  

Anyway, notice that I add 2 appointments both have 2 attributes called AdvisorID and MattTest.  I am trying to respond to the Appointment Click event client side.

I have to be doing something wrong, but I really don't know what it would be.



<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadSchedSA.aspx.cs" Inherits="CarDashboard.Pages.Service.RadSchedSA" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <script language="javascript" type="text/javascript"> function AppointmentClick(sender, eventArgs) { var appt = eventArgs.get_appointment(); var list = appt.get_attributes(); var attr = list.getAttribute('MattTest'); var count = list.get_count(); alert(count); } </script> <form id="form1" runat="server"> <div> <telerik:RadScriptManager runat="server" ID="radscriptmanager1"></telerik:RadScriptManager> <telerik:RadScheduler runat="server" ID="RadScheduler2" DisplayDeleteConfirmation="True" Width="100%" EnableEmbeddedSkins="True" Skin="Default" AllowInsert="true" AllowDelete="false" MinutesPerRow="30" ShowFooter="false" ShowAllDayRow="false" DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End" SelectedView="TimelineView" GroupingDirection="Horizontal" TimelineView-GroupingDirection="Vertical" TimelineView-HeaderDateFormat="d" TimelineView-TimeLabelSpan="1" TimeLabelRowSpan="2" TimelineView-ShowDateHeaders="True" Height="500px" TimelineView-ColumnHeaderDateFormat="HH:mm" WeekView-UserSelectable="False" MonthView-UserSelectable="False" TimelineView-ShowInsertArea="False" TimelineView-SlotDuration="0:15:00" ColumnWidth="40px" DayView-GroupingDirection="Horizontal" DayView-HeaderDateFormat="D" EnableRecurrenceSupport="False" AdvancedForm-Enabled="False" OnClientAppointmentClick ="AppointmentClick"> <ResourceStyles><telerik:ResourceStyleMapping Type="Calendar" ApplyCssClass="item" /></ResourceStyles> <AppointmentTemplate><%# Eval("Subject"%></AppointmentTemplate> </telerik:RadScheduler> </div> </form> </body> </html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Telerik.Web.UI;
using System.Linq;
 
namespace CarDashboard.Pages.Service
{
    public partial class RadSchedSA : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var appts = LoadAppointments();
                RadScheduler2.DataSource = appts;
 
                TimeSpan Daystart;
                TimeSpan Dayend;
 
                Daystart = new TimeSpan(700);
                Dayend = new TimeSpan(2000);
 
                RadScheduler2.DayStartTime = Daystart;
                RadScheduler2.DayEndTime = Dayend;
                RadScheduler2.WorkDayStartTime = Daystart;
                RadScheduler2.WorkDayEndTime = Dayend;
                RadScheduler2.TimelineView.StartTime = Daystart;
                RadScheduler2.TimelineView.NumberOfSlots = (Convert.ToInt32(Dayend.TotalHours- Convert.ToInt32(Daystart.TotalHours)) * 4// * 2 for 0:30 slots *4 for 0:15 slots
 
                RadScheduler2.Resources.Add(new Resource("Advisor""Test1""Test1 Name 1"));
                RadScheduler2.Resources.Add(new Resource("Advisor""Test2""Test1 Name 2"));
 
                ResourceType resType = new ResourceType("Advisor");
                resType.ForeignKeyField = "AdvisorID";
                RadScheduler2.ResourceTypes.Add(resType);
 
                RadScheduler2.GroupBy = "Advisor";
                RadScheduler2.DataBind();
            }
        }
 
        private List<Appointment> LoadAppointments()
        {
            List<Appointment> appts = new List<Appointment>();
 
            Appointment appt = new Appointment("1"DateTime.Now.AddMinutes(30), DateTime.Now.AddMinutes(60), "Appt 1");
            appt.Attributes.Add("AdvisorID""Test1");
            appt.Attributes.Add("MattTest""Finally 1");
            appts.Add(appt);
 
            appt = new Appointment("1"DateTime.Now.AddMinutes(-90), DateTime.Now.AddMinutes(-30), "Appt 2");
            appt.Attributes.Add("AdvisorID""Test2");
            appt.Attributes.Add("MattTest""Finally 2");
            appts.Add(appt);
 
            return appts;
        }
    }
}
0
Veronica
Telerik team
answered on 29 Sep 2010, 10:18 AM
Hello Matt,

When you add custtom attributes from code behind don't forget to add the Keys in the CustomAttributeNames in the markup:
CustomAttributeNames="AdvisorID, MattTest"

Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Shakti
Top achievements
Rank 1
answered on 08 Sep 2016, 06:47 AM

Hello Veronica,

i did same as you said to add key Name

OnClientAppointmentClick="radScheduler1_ClientAppointmentClick" CustomAttributeNames="EntityTypeId,ResourceId,ProjectId"

 

but still in the responding function i am unable to access those key

 function radScheduler1_ClientAppointmentClick(sender, args) {

.

.

var entityTypeId = args._appointment._attributes._data.EntityTypeId;

}

 

result : undefined

0
Shakti
Top achievements
Rank 1
answered on 08 Sep 2016, 06:53 AM

and in my case data is coming from database

find attachment

...

despite this .. do we have to bind details at the page level also ?

0
Veselin Tsvetanov
Telerik team
answered on 12 Sep 2016, 01:22 PM
Hello Shakti,

Attached you will find a simple implementation of the discussed scenario. You will notice that it behaves as expected and the values from the attributes collection are retrieved successfully. Could you, please double check if you have all the needed configurations on place?

Answering your second question, you will have to specify the custom attributes in the CustomAttributeNames property, to be able to load them in the attributes collection.

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Scheduler
Asked by
Matt
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Matt
Top achievements
Rank 1
Shakti
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or