+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Events Schedule View Category Filter Solved!

Events Schedule View Category Filter Solved!

24 posts, 0 answered
  1. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    11 Mar 2009
    Link to this post
    I have created a custom control to filter the Events Schedule View by category.

    1.Under ~/ControlTemplates/Events/ add new UserControl: CategoryEventsScheduleView.ascx

    2.On ascx page add:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CategoryEventsScheduleView.ascx.cs" Inherits="Sitefinity_ControlTemplates_Events_CategoryEventsScheduleView" %>

    <telerik:RadScheduler ID="EventsScheduler" runat="server" Skin="Gray" SelectedView="MonthView" Height="600px"
        OnAppointmentCreated="EventsScheduler_AppointmentCreated">
        <AppointmentTemplate>  
            <asp:HyperLink ID="EventDetailsLink" runat="server"></asp:HyperLink>  
        </AppointmentTemplate>
    </telerik:RadScheduler>

    3. In code behind add:

    sing System;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Events;
    using Telerik.Web.UI;
    using Telerik.Cms.Engine;

    public partial class Sitefinity_ControlTemplates_Events_CategoryEventsScheduleView : System.Web.UI.UserControl
    {
        /// <summary>
        /// Gets or sets the Category of the control
        /// </summary>
        public string Category
        {
            get
            {
                // if Category is empty, return ""
                if (String.IsNullOrEmpty(category))
                    return "";
                return category;
            }
            set
            {
                category = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // create instance of event manager
            EventsManager _EventsManager = new EventsManager("Events");

            // create filter by category
            List<IMetaSearchInfo> _Filter = new List<IMetaSearchInfo>();
            IList _AllEvents = null;
            if (Category.Length > 0)
            {            
                _Filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", Category, SearchCondition.Equal, JoinType.And));
            
                // get all content items filtered by category
                _AllEvents = _EventsManager.Content.GetContent(0, 0, string.Empty, string.Empty, null, string.Empty, null, _Filter.ToArray());
            
            }
            else
            {
                // get all content items with no filter
                _AllEvents = _EventsManager.Content.GetContent();
            }
            
            // set data fields for scheduler
            EventsScheduler.DataKeyField = "ID";
            EventsScheduler.DataSubjectField = "Subject";
            EventsScheduler.DataStartField = "Start";
            EventsScheduler.DataEndField = "End";

            // create new instance of appointment list
            List<Appointment> _AppointmentList = new List<Appointment>();

            // loop through content returned
            foreach (IContent _ContentItem in _AllEvents)
            {
                // get event by content id
                IEvent _EventItem = _EventsManager.GetEventByContentId(_ContentItem.ID);

                // get publication date - used for event link
                string _PublicationDateField = EventsManager.ContentSettings["Events"].PublicationDateField;
                string _PublicationDate = String.Format("{0}", _EventItem.ContentItem.GetMetaData(_PublicationDateField));

                // create new appointment
                Appointment _Appointment = new Appointment(_EventItem.ID, _EventItem.Start, _EventItem.End, String.Format("{0}+{1}", _EventItem.EventTitle, _PublicationDate));

                // remove edit/delete properties
                _Appointment.AllowEdit = false;
                _Appointment.AllowDelete = false;

                // add appointment to appointment list
                _AppointmentList.Add(_Appointment);
            }

            // set scheduler datasource to appointment list
            EventsScheduler.DataSource = _AppointmentList;
            EventsScheduler.DataBind();
        }

        protected void EventsScheduler_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
        {
            HyperLink EventDetailsLink = (HyperLink)e.Container.FindControl("EventDetailsLink");
            if (EventDetailsLink != null)
            {
                string _Title = "";
                DateTime _PublicationDate = DateTime.Now;

                // seperate title and publication date
                _Title = e.Appointment.Subject.Substring(0, e.Appointment.Subject.LastIndexOf('+'));
                _PublicationDate = Convert.ToDateTime(e.Appointment.Subject.Substring(e.Appointment.Subject.LastIndexOf('+') + 1));

                EventDetailsLink.Text = _Title;
                EventDetailsLink.NavigateUrl = String.Format("{0}/{1}/{2}/{3}?Events=EventItem", "http://staging.hoac-bsa.org", "eventdetails", String.Format("{0:yy-MM-dd}", _PublicationDate), String.Format("{0}.aspx", _Title.Replace(" ", "_")));
            }
        }

        private string category;
    }

    4. In web.config add (under toolboxControls node):

    <add name="Category Events Schedule view" section="Events" description="Show Events Schedule View by Category" url="~/Sitefinity/ControlTemplates/Events/CategoryEventsScheduleView.ascx" />

    5. When editing the control, type in the name of the Category you wish to filter by and "Presto", it works.

    6. If no Category present in textbox, the control will auto pick up all events.
    Thanks
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    20 Sep 2016
    13 Mar 2009
    Link to this post
    Hi Cody,

    Thank you for sharing your solution in our Forums!
    We have updated your Telerik account for that.

    All the best,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    01 Jun 2009
    Link to this post
    Im getting the following error. What am I missing?

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Data at the root level is invalid. Line 4, position 1.

    Source Error:

    Line 2:  
    Line 3:  
    Line 4:  using System;
    Line 5:  using System.Configuration;
    Line 6:  using System.Collections;

    Source File: /TownOfSurfside/Sitefinity/ControlTemplates/Events/App_LocalResources/CategoryEventsScheduleView.ascx.resx    Line: 4


    Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 Jun 2009
    Link to this post
    Hi shae,

    Well, judging from the error it seems you have a .resx (Resource file) which contains some c# code instead of being XML file with resources. The quick fix obviously is to remove that file from the App_LocalResources folder. Let us know what are you trying to achieve and we'll try to follow up with more guidelines.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    29 Jun 2009
    Link to this post
    Anyone know why I would get this error?

    Server Error in '/Dunwoody' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 69:             // get publication date - used for event link
    Line 70:             string _PublicationDateField = EventsManager.ContentSettings["Events"].PublicationDateField;
    Line 71:             string _PublicationDate = String.Format("{0}", _EventItem.ContentItem.GetMetaData(_PublicationDateField));
    Line 72: 
    Line 73:             // create new appointment

    Source File: c:\Program Files\Telerik\Sitefinity3.6\WebSites\Dunwoody\Sitefinity\ControlTemplates\Events\App_LocalResources\CategoryEventsScheduleView.ascx.cs    Line: 71

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Sitefinity_ControlTemplates_Events_CategoryEventsScheduleView.Page_Load(Object sender, EventArgs e) in c:\Program Files\Telerik\Sitefinity3.6\WebSites\Dunwoody\Sitefinity\ControlTemplates\Events\App_LocalResources\CategoryEventsScheduleView.ascx.cs:71
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +265
       System.Web.UI.ControlCollection.Add(Control child) +80
       Telerik.Cms.Web.PreviewPage.CreateChildControls() +2026
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    29 Jun 2009
    Link to this post
    Hello shae,

    Some of the parameters in line 70 or 71 return null value. Try debugging the code to see the exact object.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    08 Sep 2009
    Link to this post
    Thanks for the hard work on this. Its working great so far. How to you add more than one category to the calendar view? Are they just separated by a comma?
  8. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    08 Sep 2009
    Link to this post
    Just separate with a comma and you can have as many categories needed.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    08 Sep 2009
    Link to this post
    Hello mcpdinkansas,

    Another option is using ContentFilterBuilder or implementing ComplexDictionary that inherits TypeConverter and using WebEditor.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. mcpdinkansas
    mcpdinkansas avatar
    102 posts
    Registered:
    22 Mar 2007
    08 Sep 2009
    Link to this post
    Hey Ivan,

    Great idea. I might update to use one of the suggested methods when I have time.

    Thanks for the feedback.
  11. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    08 Sep 2009
    Link to this post
    Thanks for the fast response, however I cannot get it to show more than one category.

    I have two categories named:

    1. Adult Programs
    2. Special Events

    I have tried Adult Programs, Special Events   and   Adult Programs,Special Events.

    Any idea why this would not work? I'm not getting any errors, they just don't show.
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    08 Sep 2009
    Link to this post
    Hi shae,

    You could try to use ContentFilterBuilder to the listof ContentItems. You could use
    Category IN("test1", "test2")

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. shae
    shae avatar
    30 posts
    Registered:
    26 Jul 2012
    08 Sep 2009
    Link to this post
    I'm really not too sure how to implement this. Would you mind expanding on this some more?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    09 Sep 2009
    Link to this post
    Hi shae,

    You can add MetaSearchInfo filter when getting the content. You can find more information at Finding Content Items. ContentFilterBuilder cannot be used with EventsSchedule control. It requires IFilterableControl.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  15. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    14 Jul 2010
    Link to this post
    Whenever I try to implement this code with 3.7 SP3 I get the following error when I go fowards or backwards a month.  Does it work in 3.7 SP3?

    DataKeyField, DataSubjectField, DataStartField and DataEndField are required for databinding
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Jul 2010
    Link to this post
    Hi medicalwebgeek,

    These are required properties for RadScheduler control and they do not depend on Sitefinity or its version.

    Sample code

    ObjectDataSource dataSource = new ObjectDataSource();
    dataSource.ID = "EventsDataSource";
    dataSource.TypeName = "Telerik.Events.EventsManager";
    dataSource.SelectMethod = "GetEvents";
    dataSource.SelectParameters.Add("from", TypeCode.DateTime, from.ToString());
    dataSource.SelectParameters.Add("to", TypeCode.DateTime, to.ToString());
    dataSource.SelectParameters.Add("sortExpression", String.Empty);
    dataSource.SelectParameters.Add("status", ContentStatus.Published.ToString());
    dataSource.ObjectCreating += new ObjectDataSourceObjectEventHandler(dataSource_ObjectCreating);
    dataSource.Selecting += new ObjectDataSourceSelectingEventHandler(dataSource_Selecting);
    Controls.Add(dataSource);
     
     
    RadScheduler1.DataSourceID = dataSource.ID;
    RadScheduler1.DataKeyField = "ID";
    RadScheduler1.DataSubjectField = "EventTitle";
    RadScheduler1.DataStartField = "Start";
    RadScheduler1.DataEndField = "End";
    RadScheduler1.AllowDelete = false;
    RadScheduler1.AllowInsert = false;


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  17. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    14 Jul 2010
    Link to this post
    Whenever I insert the code, I get the following errors on build:

    Error 1 The name 'from' does not exist in the current context
    Error 2 The name 'to' does not exist in the current context 
    Error 3 The name 'dataSource_ObjectCreating' does not exist in the current context
    Error 4 The name 'dataSource_Selecting' does not exist in the current context 
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Jul 2010
    Link to this post
    Hi medicalwebgeek,

    You have to complete the code and create proper events which are not added to the sample. The errors you are getting are general .net errors that say there is no such object or method added.

    private DateTime from = DateTime.MinValue;
    private DateTime to = DateTime.MaxValue;
     
    .....
          .....
      private void dataSource_Selecting(object sender, EventArgs e)
        {
            ((ObjectDataSourceView)sender).SelectParameters["from"] = new Parameter("from", TypeCode.DateTime, from.ToString());
            ((ObjectDataSourceView)sender).SelectParameters["to"] = new Parameter("to", TypeCode.DateTime, to.ToString());
        }
     
        private void dataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = new EventsManager("Events");
        }

    You will find more information at

    RadScheduler


    and ObjectDataSource Web Server Control OverviewUsing Parameters with the ObjectDataSource Control

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  19. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    14 Jul 2010
    Link to this post
    I was able to get the code to work with the help of one of my co-workers. 

    Ivan - can you look at to see if you see any potential problems? 

    Here is what he changed:
      Class Name to Categories (was category)

    and he added a split:
    foreach (string category in Categories.Split(new char[] { ',' }))
                {
                    _Filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category.Trim(), SearchCondition.Equal, JoinType.And));
                }


    Full Code below:
    private string categories;
        
       private void dataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
       {
           e.ObjectInstance = new EventsManager("Events");
       }
       /// <summary>
       /// Gets or sets the Category of the control
       /// </summary>
       public string Categories
       {
           get
           {
               // if Category is empty, return ""
               if (String.IsNullOrEmpty(categories))
                   return "";
               return categories;
           }
           set
           {
               categories = value;
           }
       }
       protected void Page_Load(object sender, EventArgs e)
       {
           // create instance of event manager
           EventsManager _EventsManager = new EventsManager("Events");
           // create filter by category
           List<IMetaSearchInfo> _Filter = new List<IMetaSearchInfo>();
           IList _AllEvents = null;
           if (Categories.Length > 0)
           {
               foreach (string category in Categories.Split(new char[] { ',' }))
               {
                   _Filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category.Trim(), SearchCondition.Equal, JoinType.And));
               }
               // get all content items filtered by category
               _AllEvents = _EventsManager.Content.GetContent(0, 0, string.Empty, string.Empty, null, string.Empty, null, _Filter.ToArray());
           }
           else
           {
               // get all content items with no filter
               _AllEvents = _EventsManager.Content.GetContent();
           }
           // set data fields for scheduler
           EventsScheduler.DataKeyField = "ID";
           EventsScheduler.DataSubjectField = "Subject";
           EventsScheduler.DataStartField = "Start";
           EventsScheduler.DataEndField = "End";
           // create new instance of appointment list
           List<Appointment> _AppointmentList = new List<Appointment>();
           // loop through content returned
           foreach (IContent _ContentItem in _AllEvents)
           {
               // get event by content id
               IEvent _EventItem = _EventsManager.GetEventByContentId(_ContentItem.ID);
               // get publication date - used for event link
               string _PublicationDateField = EventsManager.ContentSettings["Events"].PublicationDateField;
               string _PublicationDate = String.Format("{0}", _EventItem.ContentItem.GetMetaData(_PublicationDateField));
               // create new appointment
               Appointment _Appointment = new Appointment(_EventItem.ID, _EventItem.Start, _EventItem.End, String.Format("{0}+{1}", _EventItem.EventTitle, _PublicationDate));
               // remove edit/delete properties
               _Appointment.AllowEdit = false;
               _Appointment.AllowDelete = false;
               // add appointment to appointment list
               _AppointmentList.Add(_Appointment);
           }
           // set scheduler datasource to appointment list
           EventsScheduler.DataSource = _AppointmentList;
           EventsScheduler.DataBind();
       }
       protected void EventsScheduler_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
       {
           HyperLink EventDetailsLink = (HyperLink)e.Container.FindControl("EventDetailsLink");
           if (EventDetailsLink != null)
           {
               string _Title = "";
               DateTime _PublicationDate = DateTime.Now;
               // seperate title and publication date
               _Title = e.Appointment.Subject.Substring(0, e.Appointment.Subject.LastIndexOf('+'));
               _PublicationDate = Convert.ToDateTime(e.Appointment.Subject.Substring(e.Appointment.Subject.LastIndexOf('+') + 1));
               EventDetailsLink.Text = _Title;
               EventDetailsLink.NavigateUrl = String.Format("{0}/{1}/{2}/{3}?Events=EventItem", "http://www.mysite.com", "eventdetails", String.Format("{0:yy-MM-dd}", _PublicationDate), String.Format("{0}.aspx", _Title.Replace(" ", "_")));
           }
       }
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Jul 2010
    Link to this post
    Hello medicalwebgeek,

    The code looks fine. The problem could appear if you have many events, because there is  one place where you call _AllEvents = _EventsManager.Content.GetContent(); In this case all events are added to the memory. It is better always to work with a given range of item if the business logic allows this.


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  21. WebGeek
    WebGeek avatar
    186 posts
    Registered:
    20 Dec 2006
    15 Jul 2010
    Link to this post
    I received this error because I had viewstate disabled on the page:
    Whenever I try to implement this code with 3.7 SP3 I get the following error when I go fowards or backwards a month.  Does it work in 3.7 SP3? 
      
    DataKeyField, DataSubjectField, DataStartField and DataEndField are required for databinding
  22. Abel Rogelio Martinez Macias
    Abel Rogelio Martinez Macias avatar
    1 posts
    Registered:
    05 Jan 2007
    30 Nov 2010
    Link to this post
    Thanks a Lot, Works Perfect CategoryEventsScheduleView Original Post
  23. Andre
    Andre avatar
    10 posts
    Registered:
    29 Dec 2011
    16 Mar 2012
    Link to this post
    Thank you so much for this. There is a slight problem.

    This comes up null:
    HyperLink EventDetailsLink = (HyperLink)e.Container.FindControl("EventDetailsLink");

    And the URL that is re-constructed from the Title sometimes doesn't translate to a valid URL if the title includes any characters other than spaces (e.x.  ( [ - "  etc).

    What is the proper way to pull the URL?

    Thanks
  24. Andre
    Andre avatar
    10 posts
    Registered:
    29 Dec 2011
    16 Mar 2012
    Link to this post
    I found the solution. If anyone has the same issue with the URL, the following version will work for you.

    using System;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Events;
    using Telerik.Web.UI;
    using Telerik.Cms.Engine;
     
    using System.ComponentModel;
    using Telerik.Framework.Web;
    using Telerik;
    using Telerik.Web;
     
    using Telerik.Events.WebControls;
    using System.Linq;
    using Telerik.Cms.Web.UI;
    using System.ComponentModel;
     
    public partial class Sitefinity_ControlTemplates_Events_CategoryEventsScheduleView : System.Web.UI.UserControl
    {
        private EventsManager eventsManager;
        private string providerName;
        private DateTime from = DateTime.MinValue;
        private DateTime to = DateTime.MaxValue;
     
        /// <summary>
        /// Name of the provider
        /// </summary>
        [System.ComponentModel.Category("Data")]
        public string ProviderName
        {
            get
            {
                if (String.IsNullOrEmpty(providerName))
                    providerName = EventsManager.DefaultContentProvider;
                return providerName;
            }
            set
            {
                providerName = value;
            }
        }
     
        /// <summary>
        /// Url of the page where single event will be displayed. That page should contain
        /// EventView control.
        /// </summary>
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms"),
        Category("Behavior")]
        public virtual string SingleEventUrl
        {
            get
            {
                object obj = ViewState["SingleEventUrl"];
                if (obj != null)
                    return (string)obj;
                return String.Empty;
            }
            set
            {
                ViewState["SingleEventUrl"] = value;
            }
        }
     
        /// <summary>
        /// Overrides the base method and registers ControlDesignerBase control as one whose control state 
        /// must be persisted.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (base.Page != null)
                base.Page.RegisterRequiresControlState(this);
     
            if (String.IsNullOrEmpty(providerName))
                providerName = EventsManager.DefaultContentProvider;
     
            if (!String.IsNullOrEmpty(providerName))
            {
                if (eventsManager == null || eventsManager.Provider.Name != providerName)
                    eventsManager = new EventsManager(providerName);
            }
        }
     
     
     
        /// <summary>
        /// Restores control state information from a previous page request that was saved by the SaveControlState
        /// method.
        /// </summary>
        /// <param name="savedState">Represents the control state to be restored.</param>
        protected override void LoadControlState(object savedState)
        {
            if (savedState != null)
            {
                object[] state = (object[])savedState;
                providerName = (string)state[0];
                from = (DateTime)state[1];
                to = (DateTime)state[2];
            }
        }
     
        /// <summary>
        /// Saves server control state changes.
        /// </summary>
        /// <returns></returns>
        protected override object SaveControlState()
        {
            return new object[] {
                    providerName,
                    from,
                    to
                };
        }
     
        /// <summary>
        /// Gets or sets the Category of the control
        /// </summary>
        public string Category
        {
            get
            {
                // if Category is empty, return ""
                if (String.IsNullOrEmpty(category))
                    return "";
                return category;
            }
            set
            {
                category = value;
            }
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            // create instance of event manager
            EventsManager _EventsManager = new EventsManager("Events");
     
            // create filter by category
            List<IMetaSearchInfo> _Filter = new List<IMetaSearchInfo>();
            IList _AllEvents = null;
            if (Category.Length > 0)
            {           
                _Filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", Category, SearchCondition.Equal, JoinType.And));
             
                // get all content items filtered by category
                _AllEvents = _EventsManager.Content.GetContent(0, 0, string.Empty, string.Empty, null, string.Empty, null, _Filter.ToArray());
             
            }
            else
            {
                // get all content items with no filter
                _AllEvents = _EventsManager.Content.GetContent();
            }
             
            // set data fields for scheduler
            EventsScheduler.DataKeyField = "ID";
            EventsScheduler.DataSubjectField = "Subject";
            EventsScheduler.DataStartField = "Start";
            EventsScheduler.DataEndField = "End";
     
     
            // create new instance of appointment list
            List<Appointment> _AppointmentList = new List<Appointment>();
     
            // loop through content returned
            foreach (IContent _ContentItem in _AllEvents)
            {
                // get event by content id
                IEvent _EventItem = _EventsManager.GetEventByContentId(_ContentItem.ID);
     
                // get publication date - used for event link
                string _PublicationDateField = EventsManager.ContentSettings["Events"].PublicationDateField;
                string _PublicationDate = String.Format("{0}", _EventItem.ContentItem.GetMetaData(_PublicationDateField));
     
                // create new appointment
                Appointment _Appointment = new Appointment(_EventItem.ID, _EventItem.Start, _EventItem.End, String.Format("{0}+{1}", _EventItem.EventTitle, _PublicationDate));
      
                // remove edit/delete properties
                _Appointment.AllowEdit = false;
                _Appointment.AllowDelete = false;
     
     
                // add appointment to appointment list
                _AppointmentList.Add(_Appointment);
            }
     
            // set scheduler datasource to appointment list
            EventsScheduler.DataSource = _AppointmentList;
            EventsScheduler.DataBind();
        }
       
        protected virtual string GetItemUrl(IContent contentItem, string singleItemUrl)
        {
            string sep = String.Empty;
            string ret = String.Empty;
            string url = singleItemUrl;
            if (String.IsNullOrEmpty(url) && CmsContext.CurrentUrl != null)
            {
                url = CmsContext.CurrentUrl.Path;
            }
            else
            {
                sep = "&";
     
                ret = String.IsNullOrEmpty(Context.Request.QueryString["ReturnURL"]) ? String.Concat("ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl)) : String.Concat("ReturnURL=", Context.Server.UrlEncode(Context.Request.QueryString["ReturnURL"]));
            }
            if (String.IsNullOrEmpty(contentItem.Url))
            {
                if (url != null)
                {
                    int idx = url.IndexOf('?');
                    if (idx != -1)
                        url = url.Substring(0, idx);
                }
                url = String.Concat(url, "?",
                    ContentManager.ContentProviderKey, "=", contentItem.ProviderName, "&",
                    ContentManager.ContentItemKey, "=", contentItem.ID, sep, ret);
            }
            else
            {
                string itemUrl = String.Concat(contentItem.Url, eventsManager.Content.Provider.ContentExtension);
                if (eventsManager.Content.Provider.UrlFormatQueryStringIndex != -1)
                {
                    itemUrl += "?" + ContentUrlRewriterService.FormatURL(contentItem, eventsManager.Content.Provider
                        , ContentUrlRewriterService.FormatOptions.QueryString);
                }
                else if (sep.Length > 0)
                {
                    sep = "?";
                }
                if (!itemUrl.StartsWith("~"))
                {
                    if (url != null)
                    {
                        int idx = url.LastIndexOf('.');
                        if (idx != -1)
                        {
                            url = url.Substring(0, idx);
                        }
                        else
                        {
                            idx = url.IndexOf('?');
                            if (idx != -1)
                                url = url.Substring(0, idx);
                        }
                    }
     
                    itemUrl = String.Concat(VirtualPathUtility.RemoveTrailingSlash(url), itemUrl);
                }
                url = String.Concat(itemUrl, sep, ret);
            }
            IUrlService svc = UrlServices.GetLanguageService();
            if (svc != null)
                return svc.ResolveLanguageUrl(url);
            return url;
        }
     
        protected void EventsScheduler_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
        {       
            IEvent _event = eventsManager.GetEvent(new Guid(e.Appointment.ID.ToString()));
            HyperLink eventDetailsLink = (HyperLink)e.Container.FindControl("eventDetailsLink");
            if (eventDetailsLink != null)
            {
                eventDetailsLink.Text = e.Appointment.Subject;
                //show description onmouse over
                eventDetailsLink.ToolTip = _event.ContentItem.Content.ToString();
                eventDetailsLink.NavigateUrl = GetItemUrl(_event.ContentItem, SingleEventUrl);
            }
             
        }
     
        private string category;
    }
Register for webinar
24 posts, 0 answered