Get Sitefinity Events from API

Posted on: Wed Sep 08 18:04:39 -0700 2010. Updated on: Wed Sep 08 19:52:20 -0700 2010.
Category: Telerik Controls and Sitefinity

Here is a quick example to get sitefinity events via the API, bind them to something that is better typed and then easily output to screen.

public static Collection GetMostRecentEvents()
		{
			EventsManager eventsMgr = new EventsManager("Events");

			IList rawEvents = eventsMgr.GetEvents();

			List listOfEvents = new List();

			foreach (Telerik.Events.IEvent eventItem in rawEvents)
			{
				listOfEvents.Add(new DataTransferObjects.EventSummaryDTO(eventItem.Start, eventItem.EventTitle, eventItem.ID));
			}

			var query = from e in listOfEvents
						orderby e.StartTime descending
						select e;

			return new Collection(query.Take(4).Reverse().ToList());
		}

And the object you can easily bind with any datasource, ie a gridview, radgrid, listview, etc

public class EventSummaryDTO
	{
		public EventSummaryDTO(DateTime startTime, string eventTitle, Guid eventId)
		{
			this.EventId = eventId;
			this.EventTitle = eventTitle;
			this.StartTime = startTime;
		}

		public DateTime StartTime { get; set; }
		public string EventTitle { get; set; }
		public Guid EventId { get; set; }
	}

Sitefinity User Control Property Help Attribute

Posted on: Wed Aug 25 12:54:21 -0700 2010. Updated on: Wed Aug 25 12:55:20 -0700 2010.
Category: Telerik Controls and Sitefinity

In Sitefinity, when you have custom user controls and you want to give your properties those little Help question marks with text in them, you can use this:


[System.ComponentModel.Description("My Help text in here")] 
public string MyProperty {get;set;}

RadGrid Default Filter Settings

Posted on: Fri Aug 20 16:44:04 -0700 2010. Updated on: Fri Aug 20 16:44:04 -0700 2010.
Category: Telerik Controls and Sitefinity

Here is a set of good filter settings to go on each RadGrid row. This is what I feel is user friendly, eliminating a lot of the usual unnecessary stuff:

AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"

this is applied on each GridBoundColumn item with allowfiltering=true on the grid itself.

Get RadGrid Datakey item id from itemcommand

Posted on: Fri Aug 20 16:39:45 -0700 2010. Updated on: Fri Aug 20 16:40:30 -0700 2010.
Category: Telerik Controls and Sitefinity

This is useful when you have a RadGrid with a codebehind ItemCommand that gets executed when action is done on a particular row. This will get you the datakey id, ie the Primary Key of the row object

protected void RadGridNonAffiliateUsers_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
		{
			if (e.CommandName == "makeAffiliate")
			{
				Guid userId = new Guid(RadGridNonAffiliateUsers.MasterTableView.DataKeyValues[e.Item.ItemIndex]["CategoryId"].ToString());
				AffiliateDO.MakeUserAffiliate(userId);

				RadGridNonAffiliateUsers.DataBind();
			}
		}

Sitefinity Find Generic Content By Name

Posted on: Mon Aug 16 13:49:18 -0700 2010. Updated on: Mon Aug 16 13:50:29 -0700 2010.
Category: Telerik Controls and Sitefinity

Find a generic content item in sitefinity by it's name and access the text...

using Telerik.Cms.Engine;
...

ContentManager contentMngr = new ContentManager();
IContent wordOfDay = contentMngr.GetContent(WordOfDayContentItem);
if (wordOfDay != null)
{
	LabelWordOfTheDay.Text = wordOfDay.Content as string;
}

Sitefinity RadEditor Adding Custom Styles

Posted on: Thu May 27 16:23:45 -0700 2010. Updated on: Thu May 27 16:26:19 -0700 2010.
Category: Telerik Controls and Sitefinity

The first thing you should do in your App_Themes/YourThemeName/ is have your styles seperated out into two files. One that would be included in the rad editor as well as your page and one that would be only for your site. The reason is that you don't want some weird body styles getting applied inside the rad editor.

Once you have that done, simply edit one of the following files:
/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml

This is the ToolsFile that is included in the radeditor ie. for Generic COntent editing. Now, you can add a css files node under the root node like this:


    
  

You can also modify this same file under the classes node and add in which styles should be available to the end user while editing in the RadEditor. There should already be an example in here.

Use Telerik Jquery library

Posted on: Wed May 05 22:33:44 -0700 2010. Updated on: Wed May 05 22:39:34 -0700 2010.
Category: Telerik Controls and Sitefinity

If you use Telerik controls and want to use jquery scripts in your stuff, you should pull the library from telerik. The best practice way of doing this is outline below. First, add the right script references, a typical script ref in your masterpage could look like this:


		
			
			

            
		
	

Next, at the end of your jquery functions, in the (_) at the end, replace 'jquery' for '$telerik.$' , without quotes of course.

(function($) {

		var modaldialog = {};
... your code here
})($telerik.$);

Globalization Culture Property list

Posted on: Fri Feb 19 15:02:41 -0800 2010. Updated on: Fri Feb 19 15:03:36 -0800 2010.
Category: Telerik Controls and Sitefinity

Some of the Telerik controls offer a Culture property setting. Here is a list of what these can be set to.

System.Globalization Cultures list

This is useful for example in the RadDatePicker control, to be able to change the date format string, ie. using european standards that use the day-month-year order. You would set the Culture property to "en-GB" for example to achieve this.

Telerik controls that use this: RadCalendar CultureInfo
RadDatePicker Culture
RadTimePicker Culture
RadDateTimePicker Culture

RadGrid Filter case insensitive

Posted on: Thu Feb 11 17:35:23 -0800 2010. Updated on: Thu Feb 11 17:36:35 -0800 2010.
Category: Telerik Controls and Sitefinity

Very easy to do, I never though it was possible. Simply add the GroupingSettings CaseSensitive="false" in the rad grid.

  

Truncate String in RadGrid or GridView

Posted on: Fri Feb 05 15:10:10 -0800 2010. Updated on: Fri Feb 05 15:43:12 -0800 2010.
Category: Telerik Controls and Sitefinity

Sometimes on display, when we have fields that may contain long text, we want to truncate the max length that is displayed on screen. It is easy to do this. First change the column into a Template, then when binding call a function you define.

// put this method in your code behind
protected string TruncateString(object stringToValidate)
		{
			string output = Convert.ToString(stringToValidate);
			
			if (output.Length > 30)
			{
				return output.Substring(0, 30) + "...";
			}
			else
			{
				return output;
			}
		}

Now in your template in the RadGrid, simply do this when outputting the text:
TruncateString(Eval("PartnerNotes"))

Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.