previous daynext daytoday
You can use templates to customize the edit form and the way appointments are rendered in RadScheduler. This example uses the following:
It also uses the FormCreated event to set default values of controls inside the templates.
Important: For the sake of simplicity the advanced insert/edit templates in this example do not support Modal mode. Please see Use custom modal advanced template and the Advanced Templates demo for more information on how to enable such support in your templates.
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Telerik.Web.Examples.Scheduler.Templates.DefaultCS" CodeFile="DefaultCS.aspx.cs" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %><%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %><%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %><%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %><%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <qsf:HeadTag ID="Headtag1" runat="server" /> <link rel="stylesheet" href="styles.css" type="text/css" /> <script type="text/javascript"> function pageLoad(sender, eventArgs) { // Prevent the double click event from bubbling out of the inline template $telerik.$(".rsAptEditSizingWrapper").bind("dblclick", function (e) { e.stopPropagation(); }); } </script> <style type="text/css"> .rsCustomAppointmentContainer div { width: 100% !important; } .rsCustomAppointmentContainer h2 { overflow: hidden !important; white-space: nowrap !important; text-overflow: ellipsis !important; } </style></head><body class="BODY"> <form id="Form1" method="post" runat="server"> <qsf:Header ID="Header1" runat="server" NavigationLanguage="C#" /> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadScheduler1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadScheduler1" LoadingPanelID="RadAjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> <telerik:RadScheduler runat="server" ID="RadScheduler1" SelectedDate="2012-04-16" DayStartTime="08:00:00" DayEndTime="18:00:00" ShowViewTabs="false" StartEditingInAdvancedForm="false" DataSourceID="AppointmentsDataSource" DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID" OnAppointmentCommand="RadScheduler1_AppointmentCommand" OnFormCreated="RadScheduler1_FormCreated" OnFormCreating="RadScheduler1_FormCreating" OnAppointmentCreated="RadScheduler1_AppointmentCreated"> <ResourceTypes> <telerik:ResourceType KeyField="ID" Name="AppointmentType" TextField="Keyword" ForeignKeyField="AppointmentTypeID" DataSourceID="AppointmentTypesDataSource" /> </ResourceTypes> <ResourceStyles> <telerik:ResourceStyleMapping Type="AppointmentType" Text="technical" ApplyCssClass="rsCategoryGreen" /> <telerik:ResourceStyleMapping Type="AppointmentType" Text="specification_review" ApplyCssClass="rsCategoryOrange" /> <telerik:ResourceStyleMapping Type="AppointmentType" Text="code_review" ApplyCssClass="rsCategoryBlue" /> </ResourceStyles> <InlineInsertTemplate> <div id="InlineInsertTemplate" class="rsCustomAppointmentContainer technical"> <div> </div> <span class="rsCustomAppointmentContainerInner"> <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>' Width="90%" TextMode="MultiLine" Height="20px"></asp:TextBox> <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert"> <asp:Image runat="server" ID="insertImage" ImageUrl="Images/ok.png" AlternateText="insert" /> </asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"> <asp:Image runat="server" ID="Image2" ImageUrl="Images/cancel.png" AlternateText="cancel" /> </asp:LinkButton> <span class="inline-label">Color code:</span> <asp:RadioButtonList runat="server" ID="AppointmentTypeRadioButtonList" DataValueField="ID" CssClass="AppointmentTypeSelectorTable" DataSourceID="AppointmentTypesDataSource" SelectedValue='<%# Bind("AppointmentTypeID") %>' DataTextField="Keyword" RepeatDirection="Horizontal" DataTextFormatString="<span class='AppointmentTypeSelector rsAptType_{0}'></span>"> </asp:RadioButtonList> <asp:LinkButton ID="InsertMoreButton" runat="server" CommandName="More" CssClass="rsAdvancedEditLink">Advanced</asp:LinkButton> </span> </div> </InlineInsertTemplate> <InlineEditTemplate> <div id="InlineEditTemplate" class="rsCustomAppointmentContainer <%# Eval("AppointmentType.Text") %>"> <div> </div> <span class="rsCustomAppointmentContainerInner"> <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>' Width="90%" TextMode="MultiLine" Height="20px"></asp:TextBox> <asp:LinkButton ID="InsertButton" runat="server" CommandName="Update"> <asp:Image runat="server" ID="insertImage" ImageUrl="Images/ok.png" AlternateText="update" /> </asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"> <asp:Image runat="server" ID="Image3" ImageUrl="Images/cancel.png" AlternateText="cancel" /> </asp:LinkButton> <span class="inline-label">Color code:</span> <asp:RadioButtonList runat="server" ID="AppointmentTypeRadioButtonList" DataValueField="ID" CssClass="AppointmentTypeSelectorTable" DataSourceID="AppointmentTypesDataSource" SelectedValue='<%# Bind("AppointmentTypeID") %>' DataTextField="Keyword" RepeatDirection="Horizontal" DataTextFormatString="<span class='AppointmentTypeSelector rsAptType_{0}'></span>"> </asp:RadioButtonList> <asp:LinkButton ID="InsertMoreButton" runat="server" CommandName="More" CssClass="rsAdvancedEditLink">Advanced</asp:LinkButton> </span> </div> </InlineEditTemplate> <AppointmentTemplate> <div class="rsCustomAppointmentContainer <%# Eval("AppointmentType.Text") %>"> <h2> <%# Eval("Subject") %> </h2> <div> </div> </div> </AppointmentTemplate> <AdvancedEditTemplate> <div id="qsfexAdvEditWrapper"> <div id="qsfexAdvEditInnerWrapper" class='<%# Eval("AppointmentType.Text") %>'> <div class="qsfexAdvAppType"> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="TitleTextBox" runat="server" CssClass="inline-label">Description</asp:Label> <asp:TextBox ID="TitleTextBox" Rows="5" Columns="20" runat="server" Text='<%# Bind("Subject") %>' Width="97%" TextMode="MultiLine"></asp:TextBox><br /> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="StartInput" runat="server" CssClass="inline-label">Start time:</asp:Label> <telerik:RadDateInput ID="StartInput" SelectedDate='<%# Bind("Start") %>' runat="server" _EnableOldBoxModel="true" EnableSingleInputRendering="false" > </telerik:RadDateInput><br /> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="EndInput" runat="server" CssClass="inline-label">End time:</asp:Label> <telerik:RadDateInput ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server" EnableSingleInputRendering="false"> </telerik:RadDateInput><br /> </div> <div class="qsfexAdvEditControlWrapper"> <div class="inline-label"> Color code:</div> <div id="qsfexAdvEditColorCodeChooser"> <asp:RadioButtonList runat="server" ID="AppointmentTypeRadioButtonList" DataValueField="ID" CssClass="AppointmentTypeSelectorTable" DataSourceID="AppointmentTypesDataSource" SelectedValue='<%# Bind("AppointmentTypeID") %>' DataTextField="Keyword" RepeatDirection="Horizontal" DataTextFormatString="<span class='AppointmentTypeSelector rsAptType_{0}'></span>"> </asp:RadioButtonList> </div> </div> <div class="qsfexAdvEditControlWrapper"> <asp:CheckBox ID="RepeatCheckBox" runat="server" Text="Repeat for 10 days" CssClass="repeatCheckBox" /> </div> <div class="qsfexAdvEditControlWrapper" style="text-align: right;"> <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update"> <asp:Image runat="server" ID="insertImage" ImageUrl="Images/ok.png" AlternateText="update" /></asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Style="margin-right: 8px;"> <asp:Image runat="server" ID="Image2" ImageUrl="Images/cancel.png" AlternateText="cancel" /></asp:LinkButton> </div> </div> </div> </AdvancedEditTemplate> <AdvancedInsertTemplate> <div id="qsfexAdvEditWrapper"> <div id="qsfexAdvEditInnerWrapper" class="technical"> <div class="qsfexAdvAppType"> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="TitleTextBox" runat="server" CssClass="inline-label">Description</asp:Label> <asp:TextBox ID="TitleTextBox" Rows="5" Columns="20" runat="server" Text='<%# Bind("Subject") %>' Width="97%" TextMode="MultiLine"></asp:TextBox><br /> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="StartInput" runat="server" CssClass="inline-label">Start time:</asp:Label> <telerik:RadDateInput ID="StartInput" SelectedDate='<%# Bind("Start") %>' runat="server" EnableSingleInputRendering="false"> </telerik:RadDateInput><br /> </div> <div class="qsfexAdvEditControlWrapper"> <asp:Label AssociatedControlID="EndInput" runat="server" CssClass="inline-label">End time:</asp:Label> <telerik:RadDateInput ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server" EnableSingleInputRendering="false"> </telerik:RadDateInput><br /> </div> <div class="qsfexAdvEditControlWrapper"> <div class="inline-label"> Color code:</div> <div id="qsfexAdvEditColorCodeChooser"> <asp:RadioButtonList runat="server" ID="AppointmentTypeRadioButtonList" DataValueField="ID" CssClass="AppointmentTypeSelectorTable" DataSourceID="AppointmentTypesDataSource" SelectedValue='<%# Bind("AppointmentTypeID") %>' DataTextField="Keyword" RepeatDirection="Horizontal" DataTextFormatString="<span class='AppointmentTypeSelector rsAptType_{0}'></span>"> </asp:RadioButtonList> </div> </div> <div class="qsfexAdvEditControlWrapper"> <asp:CheckBox ID="RepeatCheckBox" runat="server" Text="Repeat for 10 days" CssClass="repeatCheckBox" /> </div> <div class="qsfexAdvEditControlWrapper" style="text-align: right;"> <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert"> <asp:Image runat="server" ID="Image4" ImageUrl="Images/ok.png" AlternateText="update" /></asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Style="margin-right: 8px;"> <asp:Image runat="server" ID="Image5" ImageUrl="Images/cancel.png" AlternateText="cancel" /></asp:LinkButton> </div> </div> </div> </AdvancedInsertTemplate> <TimeSlotContextMenuSettings EnableDefault="true" /> <AppointmentContextMenuSettings EnableDefault="true" /> </telerik:RadScheduler> <sds:SessionDataSource ID="AppointmentsDataSource" runat="server" DisplayWarning="true" PrimaryKeyFields="ID" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" SelectCommand="SELECT * FROM [Templates_Appointments]" InsertCommand="INSERT INTO [Templates_Appointments] ([Subject], [Start], [End], [AppointmentTypeID], [RecurrenceRule], [RecurrenceParentID]) VALUES (@Subject, @Start, @End, @AppointmentTypeID, @RecurrenceRule, @RecurrenceParentID)" UpdateCommand="UPDATE [Templates_Appointments] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [AppointmentTypeID] = @AppointmentTypeID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE (ID = @ID)" DeleteCommand="DELETE FROM [Templates_Appointments] WHERE [ID] = @ID"> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="ID" Type="Int32" /> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Start" Type="DateTime" /> <asp:Parameter Name="End" Type="DateTime" /> <asp:Parameter Name="AppointmentTypeID" Type="Int32" /> <asp:Parameter Name="RecurrenceRule" Type="String" /> <asp:Parameter Name="RecurrenceParentID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Start" Type="DateTime" /> <asp:Parameter Name="End" Type="DateTime" /> <asp:Parameter Name="AppointmentTypeID" Type="Int32" /> <asp:Parameter Name="RecurrenceRule" Type="String" /> <asp:Parameter Name="RecurrenceParentID" Type="Int32" /> </InsertParameters> </sds:SessionDataSource> <sds:SessionDataSource ID="AppointmentTypesDataSource" runat="server" DisplayWarning="false" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" SelectCommand="SELECT * FROM [Templates_AppointmentTypes]"> </sds:SessionDataSource> <qsf:Footer runat="server" ID="Footer1" /> </form> <script type="text/javascript"> var $ = $telerik.$; // Toggles the inline form style when choosing a resource from the radio buttons. $('.AppointmentTypeSelectorTable input[type=radio]').live('click', function () { appType = $('input ~ label > span', this.parentNode)[0].className.match(/rsAptType_(.+?)\b/i)[1]; var parentElement = $(this).parents('.rsCustomAppointmentContainer'); if (parentElement.length == 0) { var parentElement = $(this).parents('#qsfexAdvEditInnerWrapper'); if (parentElement.length == 0) return; parentElement.attr('className', appType); } else { parentElement.attr('className', 'rsCustomAppointmentContainer ' + appType); } }); </script></body></html>
Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.
Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.
If you have any questions, do not hesitate to contact us at sales@telerik.com.