Populating RadCalander Special Days from Sitefinity Events
Hello Friends,
I have been working with Sitefinity for a little over a year, and it has spurred my quest of taking my HTML skills to the next level and moving from Web Designer to Web Developer.
So I have a book on ASP.NET and have been going though it and have become somewhat comfortable working with code behind and all that jazz.
Currently I have created a custom widget (control) and registered it with sitefinity. My widget houses a telerik RadCalander.
Is what I would like to accomplish is to be able to create events in the Sitefinity backend, tag those events with specific categories and have the dates that show up as Special Days on my RadCalander with a specific color border based on the category. Then when you hover over that specific date the body of that even is the ToolTip of the special day.
Any pointers, hints or steps in the right direction would be greatly appreciated.
-Tyler
Well, I kind of figured it out. This is my following code :
var eventitems = App.WorkWith().Events().Get().ToList();
foreach (Event element in eventitems)
DateTime d = element.EventStart;
Telerik.Web.UI.RadCalendarDay day = new Telerik.Web.UI.RadCalendarDay();
string eventInformation = element.Content;
day.Date = d;
day.ToolTip = eventInformation;
day.ItemStyle.CssClass = "TestClass";
homeCalander.SpecialDays.Add(day);
Hello,
You can filter events and other content items by category by getting the value of the category field with the GetValue extension method. Here is an example for news items. The approach with events is the same:
NewsManager newsManager = NewsManager.GetManager();
var news = newsManager.GetNewsItems().Where(newsItem => newsItem.Status == ContentLifecycleStatus.Live).ToList();
var tMan =Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetManager();
var myCat = tMan.GetTaxa<HierarchicalTaxon>().Where(t => t.Name ==
"myCategory"
).SingleOrDefault().Id;
var myList =
new
List<Telerik.Sitefinity.News.Model.NewsItem>();
for
(var i = 0; i < news.Count; i++)
var category = news[i].GetValue<TrackedList<Guid>>(
"Category"
);
if
(category.Contains(myCat))
myList.Add(news[i]);
Eureka!
You know, I've been so close. I actually saw that post probably 20 times, but whenever I was trying to use the GetValue() method it was showing up red. Typically I can highlight it and VisualStudio will add the reference for me.
I was simply missing the Using Telerik.Sitefinity.Model;
Such a rookie mistake. :\
Here is my code if anyone is interested:
//Get the ID from the GetCategoryByTitle() Method
var catID = GetCategoryByTitle("Calender - Close Date");
Guid id1 = catID.Id;
//Get a list of all the events with the category ID found above
var eventitems = App.WorkWith().Events().Get()
.Where(t => t.Status == ContentLifecycleStatus.Live)
.Where(t => t.GetValue<
TrackedList
<Guid>>("Category").Contains(id1))
.ToList();
//Loop through events and add them to the Calander
foreach (Event element in eventitems)
DateTime d = element.EventStart;
Telerik.Web.UI.RadCalendarDay day = new Telerik.Web.UI.RadCalendarDay();
string eventInformation = element.Content;
day.Date = d;
day.ToolTip = eventInformation;
day.ItemStyle.CssClass = "Closed";
day.IsSelectable = false;
homeCalander.SpecialDays.Add(day);
public Taxon GetCategoryByTitle(string title)
var taxonomyMgr = TaxonomyManager.GetManager();
HierarchicalTaxonomy category = taxonomyMgr.GetTaxonomies<
HierarchicalTaxonomy
>().Where(x => x.Name == "Categories").SingleOrDefault();
if (category == null)
return null;
return category.Taxa.Where(x => x.Title == title).SingleOrDefault();
Hi,
I am glad to hear that you have managed to filter the events by category using the information and sample I have sent you. Thank you for sharing your solution with the community.
All the best,
Stefani Tacheva
the Telerik team