0

Newbie question about using the DateTime method to set a schedule inside a Telerik calendar. I want to use the Telerik controls calendar to set a schedule for a music bands tour schedule.

I can't seem to get the desired results. Below is the code in my SampleAppointmentSource CS file. I thought that by setting the DateTime.Parse("5/19/2013") that then in all of the appointments when I use the AddDays(1) or AddDays(20) the appointemnts would follow the DateTime.Parse("5/19/2013") pattern but it doesn't. The appointments always use the current date and time (Now). When I add the days, the appointments aren't added to the Parsed date ("5/19/2013"), they are added to the current DateTime. Like the appointments are always referenced to the current system date.

I hope that wasn't to confusing....

What do I need to use to get the desired results?

Is it because of the DateTime.Now.AddDays(1) line? Should it not be DateTime.Now?

{
public class SampleAppointmentSource : AppointmentSource
{
    public SampleAppointmentSource()
    {
        DateTime date = new DateTime();
        date = DateTime.Parse("5/19/2013");
    }

    public override void FetchData(DateTime startDate, DateTime endDate)
    {
        this.AllAppointments.Clear();

        this.AllAppointments.Add(new SampleAppointment()
        {
            StartDate = DateTime.Now.AddDays(1),
            EndDate = DateTime.Now.AddDays(1),
            Subject = "Jackson W/Warren Hayes",
            AdditionalInfo = "Fain Feild",
            Location = "LoserVille,Kentucky",
        });
4

1 回答 1

1

充实我对您的问题的评论。您创建了一个DateTime名为的对象date并且从不使用它。DateTime.Now 将始终返回一个包含当前DateTime. 您需要给您的dateDateTime 对象模块级别范围,以便您可以在您的FetchData方法中访问它。看看这样的东西是否适合你。

public class SampleAppointmentSource : AppointmentSource
{
    DateTime date;
    public SampleAppointmentSource()
    {
        date = DateTime.Parse("5/19/2013");
     }

    public override void FetchData(DateTime startDate, DateTime endDate)
    {
        this.AllAppointments.Clear();

        this.AllAppointments.Add(new SampleAppointment()
        {
            StartDate = date.AddDays(1),
            EndDate = date.AddDays(1),
            Subject = "Jackson W/Warren Hayes",
            AdditionalInfo = "Fain Feild",
            Location = "LoserVille,Kentucky",
        });
    }
}
于 2013-05-13T05:54:49.923 回答