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

[Solved] jump to an appointment

18 Answers 392 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
JK
Top achievements
Rank 1
JK asked on 09 Oct 2007, 03:30 PM
Hi,
If I have the appointment ID (obtained in another SQL table which I link with) can I get the scheduller to jump to that appointment programatically (C#).

Not able to reference the demo at the moment appears to be internet dropouts at the moment, lucky to get this posted :).

Thanks,

JK.

18 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 10 Oct 2007, 09:15 AM
Hello JK,

Thank you for your interest in RadScheduler.

You can navigate to a specific appointment using the following approach:
protected void Button1_Click(object sender, EventArgs e)  
    {  
        RadScheduler1.SelectedDate = RadScheduler1.Appointments.FindByID(17).Start;  
    } 

This code will navigate to the appointment whose ID is 17.

Feel free to contact us if you have further questions.


Best wishes,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 18 Oct 2007, 10:37 AM
Peter,

I have applied your code to a button that should then jump to that appointment.  Although the scheduler does jump to that day of the specified appointment, for some reason the start and end dates of the view are very wrong.

The scheduler is set to start of day 6am till 8pm, but after I have clicked on the jump button the scheduler starts at 3pm till 4am!

I have also tried to adjust this via code and it has not worked:

   protected void btJumpToAppointment_Click(object sender, EventArgs e)  
    {  
        Telerik.Web.UI.RadScheduler Scheduler = (Telerik.Web.UI.RadScheduler)RadMultiPage1.PageViews[1].FindControl("RadScheduler1");   
        TextBox Appointment = (TextBox)fvNewService2.FindControl("txAppointmentID");  
        int starttime = int.Parse(Appointment.Text);  
 
        string thedate = Scheduler.Appointments.FindByID(starttime).Start.ToString();  
 
        string Startdate = thedate.Substring(1, 10).ToString() + " 06:00:00"// tried this and it did nothing  
 
        Scheduler.SelectedDate = DateTime.Parse(Startdate.ToString());  
        Scheduler.DayStartTime = TimeSpan.Parse("06:00:00"); // tried this and it did nothing  
 
        Scheduler.DayEndTime = TimeSpan.Parse("20:00:00"); // tried this and it did nothing  
        //Scheduler.Rebind(); ----this didnt work  
        //Scheduler.DataBind(); ---- this didnt work  
        Scheduler.SelectedView = Telerik.Web.UI.SchedulerViewType.DayView;  
        rdAppointmentAlreadyCreated.Visible = false;  
    } 

Here is the scheduler code:
<telerik:RadScheduler ID="RadScheduler1"  runat="server" DataEndField="EndDate" DataKeyField="AppointmentID" 
                                            DataRecurrenceField="RecurrenceStorage" DataRecurrenceParentKeyField="RecurrenceParentKey" 
                                            DataSourceID="MYAPPOINTMENTS" DataStartField="StartDate" DataSubjectField="Subject" 
                                            DayEndTime="20:00:00" DayStartTime="06:00:00" HoursPanelTimeFormat="HH:mm" MinutesPerRow="60" 
                                            OnAppointmentCancelingEdit="RadScheduler1_AppointmentCancelingEdit" OnAppointmentCreated="RadScheduler1_AppointmentCreated" 
                                            OnAppointmentDelete="RadScheduler1_AppointmentDelete" OnFormCreated="RadScheduler1_FormCreated" 
                                            OnFormCreating="RadScheduler1_FormCreating" SelectedDate="2007-10-01" SelectedView="WeekView" 
                                            Skin="WebBlue" TimeLabelRowSpan="1" TimeZoneOffset="00:00:00" WorkDayEndTime="19:00:00" 
                                            WorkDayStartTime="08:00:00" OverflowBehavior="Expand" FirstDayOfWeek="Monday" Height="250px" LastDayOfWeek="Sunday" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" ShowAllDayRow="False" ShowFooter="False" DataMember="DefaultView" MonthVisibleAppointmentsPerDay="10">  
                                            <ResourceTypes> 
                                                <telerik:ResourceType DataSourceID="MYEMPLOYEES" ForeignKeyField="EmployeeID" KeyField="EmployeeID" 
                                                    Name="Resource Type 0" TextField="resolvedname" /> 
                                            </ResourceTypes> 
                                        </telerik:RadScheduler> 

Can your replicate this at all?

thanks,

JK
0
JK
Top achievements
Rank 1
answered on 18 Oct 2007, 10:54 AM
Additional!

initally, my scheduler was in a rad multipage.  i was told some time ago about an incompatability with these controls.  So on a hunch I took it out of a multipage and recoded.  It still happens but now the start of day and end of day times have now moved to 12pm to 1am! instead of 3pm till 4am.

Very very strange, dont know if that little chestnut will help??

JK
0
Peter
Telerik team
answered on 19 Oct 2007, 02:05 PM
Hi Jon,

Please, try the following approach:
 protected void Button2_Click(object sender, EventArgs e)  
    {  
        Appointment appt = RadScheduler1.Appointments.FindByID(17);  
        RadScheduler1.SelectedDate = RadScheduler1.UtcDayStart(appt.Start);  
    } 

This approach will work in all cases, regardless of whether you set the TimeZoneOffset property or not.

Reviewing my previous suggestion I noticed that it is no precise. Actually,  the SelectedDate should be set to the day of the Start time:

 RadScheduler1.SelectedDate = RadScheduler1.Appointments.FindByID(17).Start.Date;  

Let us know how it goes.


Kind regards,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 19 Oct 2007, 02:16 PM
Peter,
FANTASTIC!!!!!!  Thanks your a star!!!!

Jon
0
Mark
Top achievements
Rank 1
answered on 26 Jan 2008, 11:34 AM

I'm having some trouble running this code from the scheduler load handler:


protected void RadScheduler1_Load(object sender, EventArgs e)
{
        
if (Request.QueryString["appt_id"] != null)
        {
            string appt_id = Request.QueryString["appt_id"];
            
RadScheduler1.SelectedDate = RadScheduler1.Appointments.FindByID(appt_id).Start.Date;
            RadCalendar1.Enabled =
true;
            RadScheduler1.Enabled =
true;
         }
 }

In the debugger I can see that the appt_id I'm sending is valid.  Also the RadScheduler.SelectedDate does show a valide selected date.  It's as thought the appointments collection doesn't exist or is empty.

Thanks
Mark
0
T. Tsonev
Telerik team
answered on 28 Jan 2008, 06:43 AM
Hello Mark,

Be sure to cast/convert the appt_id to the correct type. It should be the same as that used in your data source. For example, if you are using int as primary key:

int appt_id; 
if (int.TryParse(Request.QueryString["appt_id"], out appt_id) 
    // ... 

The FindByID method matches both the value and the type of the key.

Kind regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 28 Jan 2008, 09:51 AM
Hi Tsvetomir

Thanks for the reply.  I've changed the code as follows:

int appt_id;
if (int.TryParse(Request.QueryString["appt_id"], out appt_id))
{
    
RadScheduler1.SelectedDate = RadScheduler1.Appointments.FindByID(appt_id).Start.Date;
}

In the debugger I can see the value of appt_id is correctly assigned.  Unfortunately I get a null reference exception.   Is it possible the scheduler load handler is not a good place for this test?  Does the scheduler need to be in some particular state in advance of this call? 

Thanks for your help
Mark

0
T. Tsonev
Telerik team
answered on 28 Jan 2008, 01:53 PM
Hello Mark,

Sorry, I did not notice that you were doing this in the Load event. The appointments are not yet populated at that moment.

You should perform the date change in the PreRenderComplete method of your page. For example:

protected override void OnPreRenderComplete(EventArgs e) 
    base.OnPreRenderComplete(e); 
 
    int appt_id; 
    if (int.TryParse(Request.QueryString["appt_id"], out appt_id)) 
    { 
            RadScheduler1.SelectedDate =     
            RadScheduler1.Appointments.FindByID(appt_id).Start.Date; 
    } 
 
    RadScheduler1.Rebind(); 

The Rebind call is needed, because RadScheduler has already setup the current view to the previously selected date.

Regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 05 Feb 2008, 02:50 AM
Nearly there.  I added your code to the OnRenderComplete event and it does indeed bring up the correct appt up in the scheduler.  Only problem now is that immediately when I hover over an appt I get a script error in the page:  'null' is null or not an object.  Double-clicking also errors with 'selected' is null or not an object. 

Any thoughts?

Thanks
Mark
0
Mark
Top achievements
Rank 1
answered on 05 Feb 2008, 02:50 AM
Nearly there.  I added your code to the OnRenderComplete event and it does indeed bring up the correct appt up in the scheduler.  Only problem now is that immediately when I hover over an appt I get a script error in the page:  'null' is null or not an object.  Double-clicking and appt also errors with 'selected' is null or not an object.  And not surprisingly the little red X to delete the appt does not appear on hovering either.

Any thoughts?

Thanks
Mark
0
T. Tsonev
Telerik team
answered on 06 Feb 2008, 12:56 PM
Hello Mark,

Sorry, I did not completely test the proposed solution. Rebinding RadScheduler in OnPreRenderComplete turns out to be problematic. I think that the best solution is to go back to changing the selected date in Page_Load, but this time we will call DataBind explicitly to ensure that the appointments are loaded.

private void Page_Load(object sender, EventArgs e) 
    RadScheduler1.DataBind(); 
 
    int appt_id; 
    if (int.TryParse(Request.QueryString["appt_id"], out appt_id)) 
    { 
        Appointment appt = RadScheduler1.Appointments.FindByID(appt_id); 
        RadScheduler1.SelectedDate = RadScheduler1.UtcToDisplay(apt.Start); 
    } 
 
    RadScheduler1.Rebind();  
 

Note, that I have added a call to UtcToDisplay when calculating the selected date. This is needed if you are using TimeZoneOffset different than 0.

Regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 10 Feb 2008, 12:42 PM
Nearly there!  Only trouble now is the range of times shown in the scheduler is off by 4hrs.  The control is set by default to show the hours 8:00am - 8:30pm, no TimeZoneOffset property set.  After targeting the date in the way we're doing, the range of times shown is 4:00pm - 4:30am.  I'm guessing it has something to do with that DispalyToUtc call? 

All my clients and servers default to US Eastern Standard Time. 

Thanks for all your help.
Mark
0
T. Tsonev
Telerik team
answered on 11 Feb 2008, 01:25 PM
Hello Mark,

The problem with my last suggestion is that I forgot to remove the hours from the Start time. Since you are working with TimeZoneOffset set to zero (default value) you can directly use the date part of the appointment's start:

RadScheduler1.SelectedDate = apt.Start.Date; 


Sincerely yours,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 20 Feb 2008, 03:09 AM
Almost but there's still an issue.  I can target the appt ok now, then... 

I can drag-and-drop the appt to another slot ok.
I can click the little red x to delete the appt ok
If I double-click the appt and bring up Advanced Edit form, the update fails. 

I notice that the AppointmentUpdate event is never fired and in sql profiler I  never see an update statement.  I do see both during drag-and-drop, just doesn't work in the advanced edit form.  There is no obvious error in the browser.

If I comment out this block from the page_load it works again, but of course I lose the appt targeting:

if (Session["appt_id"] != null)
{
    RadScheduler1.DataBind();
    int appt_id;
    
    if (int.TryParse(Session["appt_id"].ToString(), out appt_id))
    {
    Appointment appt = RadScheduler1.Appointments.FindByID(appt_id);
    RadScheduler1.SelectedDate = appt.Start.Date;
    RadCalendar1.SelectedDate = appt.Start.Date;
    RadCalendar1.FocusedDate = appt.Start.Date;
    }
    RadScheduler1.Rebind();
}



0
T. Tsonev
Telerik team
answered on 21 Feb 2008, 04:04 PM
Hello Mark,

Currently, you are calling RadScheduler.DataBind on every postback. This breaks most of its functionality, as it resets its internal state before it has the chance to process the commands coming from the browser. Some of them still get through, as you have noticed, but only by chance.

You should do the "jump" only on initial load, i.e. when IsPostBack is false.

All the best,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Nyceane
Top achievements
Rank 1
answered on 23 Jun 2008, 10:48 PM
Hey, I have a question on manually binding Resources, I can see the resources type but I can't see the resources, how do I do that?

        protected void Schedulebind(object temp)  
        {  
            Schedule.DataSource = temp; //Initial load Dr. Jones' record  
            Schedule.DataBind();  
            Schedule.ResourceTypes.FindByName("Status").DataSource = temp;   
    //      Schedule.ResourceTypes.FindByName("Status").Databind doesnt exist.
              
        } 
0
Peter
Telerik team
answered on 24 Jun 2008, 03:16 PM
Hello Nyceane,

Please, refer to the Binding To Generic List example. The code which initializes the resources is the following:

private void InitializeResources()  
        {  
            ResourceType resType = new ResourceType("User");  
            resType.ForeignKeyField = "UserID";  
 
            RadScheduler1.ResourceTypes.Add(resType);  
            RadScheduler1.Resources.Add(new Resource("User", 1, "Alex"));  
            RadScheduler1.Resources.Add(new Resource("User", 2, "Bob"));  
            RadScheduler1.Resources.Add(new Resource("User", 3, "Charlie"));  
        }  
 

Feel free to contact us if you have further questions.


Kind regards,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Scheduler
Asked by
JK
Top achievements
Rank 1
Answers by
Peter
Telerik team
JK
Top achievements
Rank 1
Mark
Top achievements
Rank 1
T. Tsonev
Telerik team
Nyceane
Top achievements
Rank 1
Share this question
or