using resources with generic list bound appts

4 posts, 0 answers
  1. Josh
    Josh avatar
    3 posts
    Member since:
    Aug 2007

    Posted 20 Sep 2007 Link to this post

    Following the online demos for Binding to Generic Lists and Defining Resources as a guide, I have attempted to use resources to style my appointments. 

    After running DataBind(), I can see that each Appointment has a resource but when the scheduler loads up, the styles are not taking effect. When I look at the page's html source, the appointment element has class="rsApt " (notice the space), not class="rsApt User".

    The Defining Resources example source shows class="rsApt Alex" or Charlie or Bob.  The Binding to Generic List examples source shows the same thing that I am seeing.

    Is this a bug, or is this functionality that is not available when binding to generic lists?  Any Ideas?
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2834 posts

    Posted 21 Sep 2007 Link to this post

    Hello Josh,

    The resource names are not automatically rendered as CSS classes. You should attach to the AppointmentCreated event and set them on the fly, as in the example:

    protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e) 
        foreach (Resource resource in e.Appointment.Resources) 
        { 
            if (resource.Type == "User"
            { 
                e.Appointment.CssClass = resource.Text; 
            } 
        } 
     


    Regards,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Ana
    Ana avatar
    1 posts
    Member since:
    Mar 2013

    Posted 08 Apr 2013 Link to this post

    As indicated in the title, I'm filling in the RadScheduler with a list (List <MyType>) and there's no way to fill in the resources.
    I developed a parser to fill appointments but when i try to access to an appointment resource it crashes.
    This is the binding code:
    protected void Page_Init(object sender, EventArgs e)
        {
              //ORIGINAL BINDING MODE
             //List<CalendarAppointment> appointments = new List<CalendarAppointment>();
                //appointments.AddRange(business.GetCalendarAppointments(calendar.Id));
     
              List<Telerik.Web.UI.Appointment> appointments = new List<Telerik.Web.UI.Appointment>();
              appointments = ParsearAppointments(business.GetCalendarAppointments(calendar.Id));
             RadScheduler1.DataSource = appointments;
             RadScheduler1.DataBind();
        }
     
    and there is the parser:
    private List<Appointment> ParsearAppointments(List<CalendarAppointment> list)
    {
        List<Appointment> appointments = new List<Appointment>();
        Telerik.Web.UI.Appointment a = new Telerik.Web.UI.Appointment();
        foreach (CalendarAppointment ap in list)
        {
            a.Subject=ap.Title;
            a.Description=ap.Description;
            a.Start=ap.StartDate;
            a.End=ap.EndDate;
            a.Attributes["Place"]=ap.Location;
            //a.Resources[0].Key=ap.CalendarId;---> it crashes here
            a.Attributes["Representant"]=ap.Representative;
           appointments.Add(a);
        }
     
        return appointments;
    }

    And the error code:

    System.ArgumentOutOfRangeException
    {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}


    I would appreciate a way to fix this issue or another way to do this.
    Ana
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 11 Apr 2013 Link to this post

    Hello,

    It seems that the problem is caused by an empty resource collection for your appointment. In order to avoid that behavior I would suggest adding a resource to that item using the following expression:
    //code behind
    a.Resources.Add(new Resource(....));

    Once you have a resource item added to the appointment resource collection, you will be able to access it by index.

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