Add appointment directly from TimeSlot Context Menus

7 posts, 1 answers
  1. Thomas
    Thomas avatar
    22 posts
    Member since:
    Mar 2011

    Posted 10 Mar 2011 Link to this post

    Hi!

    Can someone show me an example how to accomplish the following in RadScheduler?

    The user selects the desired time slots with the mouse pointer and then right click to bring up a TimeSlotContextMenu designed something like this:

    <TimeSlotContextMenus>
        <telerik:RadSchedulerContextMenu ID="SchedulerTimeSlotContextMenu" runat="server">
        <Items>
            <telerik:RadMenuItem Text="Peter" />
            <telerik:RadMenuItem Text="Adam" />
            <telerik:RadMenuItem Text="Niclas" />
            <telerik:RadMenuItem Text="Jones" />
        </Items>
        </telerik:RadSchedulerContextMenu>
    </TimeSlotContextMenus>

    Then when the user choose one of the menu items a booking should be done without poping up a booking form.

    Is it possible? If so, how do I do it?

    I'm using C# and the Rad v2010.3.1317.40.

    Sincerely, Thomas




  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 11 Mar 2011 Link to this post

    Hello Thomas,

    Here is one possible solution:
    <telerik:RadScheduler runat="server" ID="RadScheduler1" OnTimeSlotContextMenuItemClicked="RadScheduler1_TimeSlotContextMenuItemClicked"
           OnFormCreating="RadScheduler1_FormCreating">
          <TimeSlotContextMenus>
              <telerik:RadSchedulerContextMenu ID="SchedulerTimeSlotContextMenu" runat="server">
                  <Items>
                      <telerik:RadMenuItem Text="Peter" Value="CommandAddAppointment" />
                      <telerik:RadMenuItem Text="Adam" Value="CommandAddAppointment" />
                      <telerik:RadMenuItem Text="Niclas" Value="CommandAddAppointment" />
                      <telerik:RadMenuItem Text="Jones" Value="CommandAddAppointment" />
                  </Items>
              </telerik:RadSchedulerContextMenu>
          </TimeSlotContextMenus>
      </telerik:RadScheduler>


    protected Appointment CurrentAppointment
       {
           get
           {
               return Session["CurrentAppointment"] as Appointment;
           }
           set
           {
               Session["CurrentAppointment"] = value;
           }
       }
       protected void RadScheduler1_TimeSlotContextMenuItemClicked(object sender, TimeSlotContextMenuItemClickedEventArgs e)
       {
           CurrentAppointment.Subject = e.MenuItem.Text;
           RadScheduler1.InsertAppointment(CurrentAppointment);
           RadScheduler1.Rebind();
       }   
       protected void RadScheduler1_FormCreating(object sender, SchedulerFormCreatingEventArgs e)
       {
           if (e.Mode == SchedulerFormMode.Insert)
               CurrentAppointment = e.Appointment;
           e.Cancel = true;
       }


    Regards,
    Peter
    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!
  3. Thomas
    Thomas avatar
    22 posts
    Member since:
    Mar 2011

    Posted 11 Mar 2011 Link to this post

    Peter,

    I must say the support at Telerik is worldclass.
    Thank you very much, this works great!

    Can you also point me in the right direction on how to modify your code so...

    Instead of just setting the "Subject" at the appointment to the Text Value from the RadMenuItem I also would like it to insert the UserID and RoomID into the database as well (I have two SQL database tables for that).

    Another Question:
    How can I from code behind add more RadMenuItem in the RadSchedulerContextMenu?
    I want to fetch the userlist from de database at pageload and then create the RadMenu.

    Sincerely, Thomas

  4. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 12 Mar 2011 Link to this post


    Thank you for the nice words, Thomas!

    Attached is a simple demo of the required functionality. Please, test it and let me know if you have further questions.


    All the best,
    Peter
    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!
  5. Thomas
    Thomas avatar
    22 posts
    Member since:
    Mar 2011

    Posted 12 Mar 2011 Link to this post

    Peter,

    You are the man!

    Thank you very much, it works perfect!

    SIncerely, Thomas
  6. Thomas
    Thomas avatar
    22 posts
    Member since:
    Mar 2011

    Posted 13 Mar 2011 Link to this post

    What am I missing here?

    The following code works perfect when browsing around my appointments:
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
        string css_text = e.Appointment.Resources.GetResourceByType("CssId").Text;
        if (css_text == "1")
        {
            e.Appointment.CssClass = "rsCategoryDarkRed";
        }
        else if (css_text == "2")
        {
            e.Appointment.CssClass = "rsCategoryBlue";
        }
        else if (css_text == "3")
        {
            e.Appointment.CssClass = "rsCategoryGreen";
        }
        else if (css_text == "4")
        {
            e.Appointment.CssClass = "rsCategoryViolet";
        }
    }
     
    But as soon I add a new appointment(with the ContextMenu one click routine) it just give me the "Object reference not set to an instance of an object."(Line 65):
    Line 63:     protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    Line 64:     {
    Line 65:         string css_text = e.Appointment.Resources.GetResourceByType("CssId").Text;
    Line 66:         if (css_text == "1")
    Line 67:         {

    If i then reload the Scheduler Page the new appointment shows upp and the css works correct.

    SIncerely, Thomas

  7. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 15 Mar 2011 Link to this post

    Hello Thomas,

    I cant replicate this problem using the demo I sent you in the previous post. Can you modify the sample so that the problem occurs and tell us exactly what changes you have made?


    Greetings,
    Peter
    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!
Back to Top