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

How to disable the radscheduler when there's no data

1 Answer 117 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 22 Feb 2011, 11:22 AM
I've a radscheduler reading it's data in from a provider (which connects to exchange). If there's no account to connect to, or a problem with the service, I want the scheduler to simply be disabled and not render.

So I thought this simple peice of logic would do the trick:

if (Service != null)
{
    Calendar.DayStartTime = TimeSpan.Parse("05:00:00");
    Calendar.DayEndTime = TimeSpan.Parse("23:00:00");
    Calendar.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
    Calendar.WeekView.HeaderDateFormat = "d";
    ScheduleProvider ExchangeScheduleProvider = new ScheduleProvider();
    ExchangeScheduleProvider.ExchangeService = Service;
    Calendar.Provider = ExchangeScheduleProvider;
}
else
{
    Calendar.Enabled = false;
    Calendar.Visible = false;
}

However, even though the scheduler shouldn't be enabled now in theory, it seems to ignore this and is desperate to try and databind. I get the following error:

[ArgumentException: DataKeyField, DataSubjectField, DataStartField and DataEndField are required for databinding]
   Telerik.Web.UI.Scheduling.DataSourceViewSchedulerProvider.EnsureDataFieldsAreSet() +204

Nowhere in my code do I set a datasource or tell it to databind.
I don't want it to databind or do anything, how do I disable the control?

1 Answer, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 22 Feb 2011, 01:57 PM
Hi Matthew,

By default RadScheduler can not be shown without first bound to any datasource. Those fields: DataKeyField, DataSubjectField, DataStartField and DataEndField are required otherwise you'll get an error. However you can overcome this by setting those fields to some invalid strings e.g.:

DataKeyField = "a"
DataSubjectField ="a"
DataStartField = "a"
DataEndField="a"

as their values are checked only for null or empty string.

As for the RadScheduler to be disabled - please set the ReadOnly property to "true". The Enabled property comes from that the RadScheduler inherits the WebControl class and is common for all controls that inherit the WebControl class.

All the best,
Veronica Milcheva
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Scheduler
Asked by
Matthew
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Share this question
or