Telerik RadScheduler Datasource

5k Views Asked by At

I have the ff code:

// note: entries is a list binded to a query from the database
//       wherein i'm passing some parameters to satisfy
//       the conditions from the query

foreach (var entry in entries)
{
    Appointment appointment = new Appointment();
    appointment.Start = entry.StartDateTime;
    appointment.End = entry.EndDateTime;
    appointment.Summary = entry.Summary;

    this.radScheduler.Appointments.Add(appointment);
}

Is there a way to bind the entries directly to radScheduler without using foreach statement?

I've also tried using radScheduler.datasource but it doesn't work.

1

There are 1 best solutions below

0
On

Please check below code :

.aspx

<telerik:RadScheduler ID="RadScheduler1" runat="server" DataKeyField="ID" DataSubjectField="Subject"
    DataStartField="StartDate" DataEndField="EndDate" >

.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        List<MyScedule> lst = new List<MyScedule>();
        MyScedule obj = new MyScedule();
        obj.ID = 1;
        obj.Subject = "my Subject";
        obj.StartDate = DateTime.Now;
        obj.EndDate = DateTime.Now.AddHours(1);
        lst.Add(obj);

        MyScedule obj1 = new MyScedule();
        obj1.ID = 2;
        obj1.Subject = "my Subject";
        obj1.StartDate = DateTime.Now.AddHours(2);
        obj1.EndDate = DateTime.Now.AddHours(3);
        lst.Add(obj1);

        RadScheduler1.DataSource = lst;
        RadScheduler1.DataBind();
    }
}

.cs

public class MyScedule
{
    public int ID { get; set; }
    public string Subject { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
}

http://www.telerik.com/help/aspnet-ajax/scheduler-database-structure.html

It worked from my side.