This is a migrated thread and some comments may be shown as answers.

TimelineView GroupBy is not working

1 Answer 44 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Nirav
Top achievements
Rank 1
Nirav asked on 19 Mar 2012, 11:03 PM
Hello, 

We purchased Telerik control, and we are using it in our firm.

In one of my dotnet webapplication i wanted to use scheduler as TimelineView ,with GroupBy of my custom attribure field(which is combobox) here it is Initiative. 

Appointments are there with initiative field, it will display without GroupBy ,but when i will configure with GroupBy=Initiative none of the data will display in my scheduler.

Below is my code :Aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadSchedulerWebForm.aspx.cs"
    Inherits="RadSchedulerWebForm" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
 
    <script type="text/javascript">
        //Put your JavaScript code here.       
        function insertAppointment(sender, e) {
            var slot = sender.get_activeModel().getTimeSlotFromDomElement(e.get_domEvent().target);
            sender.showInsertFormAt(slot);
        }
        function editAppointment(sender, e) {
            var apt = e.get_appointment();
            sender.editAppointmentWithConfirmation(apt);
        }
    </script>
 
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadScheduler1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxPanel runat="server" RenderMode="Block" ID="ajaxPanel" EnableAJAX="true">
        <br />
        <br />
        <div>
            <asp:Label ID="lblInitiaveName" AssociatedControlID="ddlInitiave" Text="" runat="server">Show Task By Initiative:</asp:Label>
            <telerik:RadComboBox ID="ddlInitiave" DataTextField="InitiativeName" DataValueField="ID"
                Skin="Outlook" runat="server" AutoPostBack="true">
            </telerik:RadComboBox>
            <br />
            <br />
        </div>
        <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="100%" OnFormCreated="RadScheduler1_FormCreated"
            OnAppointmentInsert="RadScheduler1_AppointmentInsert" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate"
            OnAppointmentDelete="RadScheduler1_AppointmentDelete" DataKeyField="ID" DataSubjectField="Subject"
            DataStartField="Start" DataEndField="End" DataRecurrenceField="RecurrenceRule"
            DataRecurrenceParentKeyField="RecurrenceParentId" OnClientTimeSlotClick="insertAppointment"
            OnClientAppointmentClick="editAppointment" StartInsertingInAdvancedForm="True"
            AppointmentStyleMode="Default" OnAppointmentDataBound="RadScheduler1_AppointmentDataBound"
            AdvancedForm-Modal="true" CustomAttributeNames="Comments,agencyValue,statusValue,initiativeName,task,assetType"
            AdvancedForm-EnableCustomAttributeEditing="true" SelectedView="MonthView" Skin="Outlook"
            Height="100%" OverflowBehavior="Expand" EditFormDateFormat="MM/dd/yyyy" EnableCustomAttributeEditing="True"
            RowHeight="30px" >           
            <ResourceTypes>
                <telerik:ResourceType KeyField="ID" Name="Initiative" TextField="InitiativeName"
                    ForeignKeyField="ID" DataSourceID="SqlDataSourceInitiative" />
            </ResourceTypes>
            <TimelineView UserSelectable="true" GroupBy="Initiative"  GroupingDirection="Vertical" />
            <InlineInsertTemplate>
                <div id="InlineInsertTemplate">
                    <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>' TextMode="MultiLine"></asp:TextBox>
                    <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert">Insert</asp:LinkButton>
                    <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel">Cancel</asp:LinkButton>
                    <asp:LinkButton ID="InsertMoreButton" runat="server" CommandName="More">Advanced</asp:LinkButton>
                </div>
            </InlineInsertTemplate>
            <InlineEditTemplate>
                <div id="InlineEditTemplate">
                    <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>' TextMode="MultiLine"></asp:TextBox>
                    <asp:LinkButton ID="InsertButton" runat="server" CommandName="Update">Update</asp:LinkButton>
                    <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel">Cancel</asp:LinkButton>
                    <asp:LinkButton ID="InsertMoreButton" runat="server" CommandName="More">Advanced</asp:LinkButton>
                </div>
            </InlineEditTemplate>
            <AdvancedForm EnableCustomAttributeEditing="True" DateFormat="MM/dd/yyyy"></AdvancedForm>
            <AdvancedEditTemplate>
                <div class="rsAdvancedEdit rsAdvancedModal" style="position: relative">
                    <div class="rsModalBgTopLeft">
                    </div>
                    <div class="rsModalBgTopRight">
                    </div>
                    <div class="rsModalBgBottomLeft">
                    </div>
                    <div class="rsModalBgBottomRight">
                    </div>
                    <div class="rsAdvTitle">
                        <h1 class="rsAdvInnerTitle">
                            Update Schedule</h1>
                        <asp:LinkButton runat="server" ID="AdvancedEditCloseButton" CssClass="rsAdvEditClose"
                            CommandName="Cancel" CausesValidation="false" ToolTip='<%# Container.Appointment.Owner.Localization.AdvancedClose %>'>
                             <%# Container.Appointment.Owner.Localization.AdvancedClose%>
                        </asp:LinkButton>
                    </div>
                    <div class="rsAdvContentWrapper">
                        <div>
                            <asp:Label ID="lblInitiaveName" AssociatedControlID="ddlInitiaveName" Text="" runat="server">Initiative:</asp:Label>
                            <telerik:RadComboBox ID="ddlInitiaveName" DataTextField="InitiativeName" DataValueField="ID"
                                SelectedValue='<%# Bind("initiativeName") %>' runat="server">
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblTask" AssociatedControlID="ddlTask" runat="server">Task:</asp:Label>
                            <telerik:RadComboBox ID="ddlTask" DataTextField="Title" DataValueField="ID" SelectedValue='<%# Bind("task") %>'
                                runat="server">
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblAssetType" AssociatedControlID="ddlAssetType" Text="" runat="server">AssetType:</asp:Label>
                            <telerik:RadComboBox ID="ddlAssetType" DataTextField="AssetType" DataValueField="ID"
                                SelectedValue='<%# Bind("assetType") %>' runat="server">
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblTitle" AssociatedControlID="TitleTextBox" runat="server">Description:</asp:Label>
                            <telerik:RadTextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>'>
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator runat="server" ID="rfvTitleTextBox" ControlToValidate="TitleTextBox"
                                ErrorMessage="Please enter Description">
                            </asp:RequiredFieldValidator>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblAgency" AssociatedControlID="ddlAgency" runat="server">Agency:</asp:Label>
                            <telerik:RadComboBox ID="ddlAgency" runat="server" DataTextField="Text" DataValueField="Value"
                                SelectedValue='<%# Bind("agencyValue") %>'>
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblStartDate" AssociatedControlID="StartInput" runat="server">Start Date:</asp:Label>
                            <telerik:RadDateTimePicker ID="StartInput" runat="server" SelectedDate='<%# Bind("Start") %>'
                                TimeView-StartTime="09:00:00" TimeView-EndTime="17:00:00" TimeView-Interval="00:30:00"
                                TimeView-Columns="2">
                            </telerik:RadDateTimePicker>
                            <%--<telerik:RadDateInput ID="StartInput" SelectedDate='<%# Bind("Start") %>' runat="server">
                            </telerik:RadDateInput>--%><br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblEndDate" AssociatedControlID="EndInput" runat="server">End Date:</asp:Label>
                            <telerik:RadDateTimePicker ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server"
                                TimeView-StartTime="09:00:00" TimeView-EndTime="17:00:00" TimeView-Interval="00:30:00"
                                TimeView-Columns="2">
                            </telerik:RadDateTimePicker>
                            <%--<telerik:RadDateInput ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server">
                            </telerik:RadDateInput>--%><br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblStatus" AssociatedControlID="ddlStatus" runat="server">Status:</asp:Label>
                            <telerik:RadComboBox ID="ddlStatus" runat="server" DataTextField="Text" DataValueField="Value"
                                SelectedValue='<%# Bind("statusValue") %>'>
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblComments" AssociatedControlID="CommentsTextBox" runat="server">Comments:</asp:Label>
                            <telerik:RadTextBox ID="CommentsTextBox" Rows="5" Columns="20" runat="server" Text='<%# Bind("Comments") %>'
                                Width="95%" TextMode="MultiLine">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator runat="server" ID="rfvComments" ControlToValidate="CommentsTextBox"
                                ErrorMessage="Please enter Comments">
                            </asp:RequiredFieldValidator>
                            <br />
                            <br />
                        </div>
                        <asp:Panel runat="server" ID="ButtonsPanel" CssClass="rsAdvancedSubmitArea">
                            <div class="rsAdvButtonWrapper">
                                <asp:LinkButton CommandName="Update" runat="server" ID="UpdateButton" CssClass="rsAdvEditSave">
                            <span>Update</span>
                                </asp:LinkButton>
                                <asp:LinkButton runat="server" ID="CancelButton" CssClass="rsAdvEditCancel" CommandName="Cancel"
                                    CausesValidation="false">
                            <span><%# Container.Appointment.Owner.Localization.Cancel%></span>
                                </asp:LinkButton>
                            </div>
                        </asp:Panel>
                    </div>
                </div>
            </AdvancedEditTemplate>
            <AdvancedInsertTemplate>
                <div class="rsAdvancedEdit rsAdvancedModal" style="position: relative">
                    <div class="rsModalBgTopLeft">
                    </div>
                    <div class="rsModalBgTopRight">
                    </div>
                    <div class="rsModalBgBottomLeft">
                    </div>
                    <div class="rsModalBgBottomRight">
                    </div>
                    <div class="rsAdvTitle">
                        <h1 class="rsAdvInnerTitle">
                            New Schedule</h1>
                        <asp:LinkButton runat="server" ID="AdvancedEditCloseButton" CssClass="rsAdvEditClose"
                            CommandName="Cancel" CausesValidation="false" ToolTip='<%# Container.Appointment.Owner.Localization.AdvancedClose %>'>
                             <%# Container.Appointment.Owner.Localization.AdvancedClose%>
                        </asp:LinkButton>
                    </div>
                    <div class="rsAdvContentWrapper">
                        <div>
                            <asp:Label ID="lblInitiaveName" AssociatedControlID="ddlInitiaveName" Text="" runat="server">Initiative:</asp:Label>
                            <telerik:RadComboBox ID="ddlInitiaveName" DataTextField="InitiativeName" DataValueField="ID"
                                SelectedValue='<%# Bind("initiativeName") %>' runat="server">
                            </telerik:RadComboBox>
                            <asp:CompareValidator ID="initiaveValidator" runat="server" ControlToValidate="ddlInitiaveName"
                                ValueToCompare=" --- Select  Initiative --- " Operator="NotEqual" ErrorMessage="Please select Initiative"></asp:CompareValidator>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblTask" AssociatedControlID="ddlTask" runat="server">Task:</asp:Label>
                            <telerik:RadComboBox ID="ddlTask" DataTextField="Title" DataValueField="ID" SelectedValue='<%# Bind("task") %>'
                                runat="server">
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblAssetType" AssociatedControlID="ddlAssetType" Text="" runat="server">AssetType:</asp:Label>
                            <telerik:RadComboBox ID="ddlAssetType" DataTextField="AssetType" DataValueField="ID"
                                SelectedValue='<%# Bind("assetType") %>' runat="server">
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblTitle" AssociatedControlID="TitleTextBox" runat="server">Description:</asp:Label>
                            <telerik:RadTextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Subject") %>'>
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator runat="server" ID="rfvTitleTextBox" ControlToValidate="TitleTextBox"
                                ErrorMessage="Please enter Description">
                            </asp:RequiredFieldValidator>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblAgency" AssociatedControlID="ddlAgency" runat="server">Agency:</asp:Label>
                            <telerik:RadComboBox ID="ddlAgency" runat="server" DataTextField="Text" DataValueField="Value"
                                SelectedValue='<%# Bind("agencyValue") %>'>
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblStartDate" AssociatedControlID="StartInput" runat="server">Start Date:</asp:Label>
                            <telerik:RadDateTimePicker ID="StartInput" runat="server" SelectedDate='<%# Bind("Start") %>'
                                TimeView-StartTime="09:00:00" TimeView-EndTime="17:00:00" TimeView-Interval="00:30:00"
                                TimeView-Columns="2">
                            </telerik:RadDateTimePicker>
                            <%--<telerik:RadDateInput ID="StartInput" SelectedDate='<%# Bind("Start") %>' runat="server">
                            </telerik:RadDateInput>--%><br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblEndDate" AssociatedControlID="EndInput" runat="server">End Date:</asp:Label>
                            <telerik:RadDateTimePicker ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server"
                                TimeView-StartTime="09:00:00" TimeView-EndTime="17:00:00" TimeView-Interval="00:30:00"
                                TimeView-Columns="2">
                            </telerik:RadDateTimePicker>
                            <%--<telerik:RadDateInput ID="EndInput" SelectedDate='<%# Bind("End") %>' runat="server">
                            </telerik:RadDateInput>--%><br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblStatus" AssociatedControlID="ddlStatus" runat="server">Status:</asp:Label>
                            <telerik:RadComboBox ID="ddlStatus" runat="server" DataTextField="Text" DataValueField="Value"
                                SelectedValue='<%# Bind("statusValue") %>'>
                            </telerik:RadComboBox>
                            <br />
                            <br />
                        </div>
                        <div>
                            <asp:Label ID="lblComments" AssociatedControlID="CommentsTextBox" runat="server">Comments:</asp:Label>
                            <telerik:RadTextBox ID="CommentsTextBox" Rows="5" Columns="20" runat="server" Text='<%# Bind("Comments") %>'
                                Width="95%" TextMode="MultiLine">
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator runat="server" ID="rfvComments" ControlToValidate="CommentsTextBox"
                                ErrorMessage="Please enter Comments">
                            </asp:RequiredFieldValidator>
                            <br />
                            <br />
                        </div>
                        <asp:Panel runat="server" ID="ButtonsPanel" CssClass="rsAdvancedSubmitArea">
                            <div class="rsAdvButtonWrapper">
                                <asp:LinkButton CommandName="Insert" runat="server" ID="SaveButton" CssClass="rsAdvEditSave"
                                    CausesValidation="true">                                   
                                <span><%# Container.Appointment.Owner.Localization.Save%></span>
                                </asp:LinkButton>
                                <asp:LinkButton runat="server" ID="CancelButton" CssClass="rsAdvEditCancel" CommandName="Cancel"
                                    CausesValidation="false">
                            <span><%# Container.Appointment.Owner.Localization.Cancel%></span>
                                </asp:LinkButton>
                            </div>
                        </asp:Panel>
                    </div>
                </div>
            </AdvancedInsertTemplate>
            <TimeSlotContextMenus>
                <telerik:RadSchedulerContextMenu runat="server" ID="SchedulerTimeSlotContextMenu">
                    <Items>
                        <telerik:RadMenuItem Text="New Schedule" Value="CommandAddAppointment" />
                    </Items>
                </telerik:RadSchedulerContextMenu>
            </TimeSlotContextMenus>
            <TimeSlotContextMenuSettings EnableDefault="true" />
            <AppointmentContextMenuSettings EnableDefault="true" />
        </telerik:RadScheduler>
    </telerik:RadAjaxPanel>
    <br />
    <telerik:RadButton ID="btnExport" runat="server" Text="Exprot to Excel" Skin="Outlook">
    </telerik:RadButton>
    <asp:SqlDataSource ID="SqlDataSourceInitiative" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT ID,InitiativeName FROM [Initiatives]"></asp:SqlDataSource>
    <%--<telerik:RadScheduler ID="RadScheduler2" runat="server" DataEndField="End" Visible="false"
        DataKeyField="ID" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
        DataSourceID="SqlDataSource1" DataStartField="Start" DataSubjectField="Subject">
        <ResourceTypes>
            <telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="UserID" KeyField="ID"
                Name="Users" TextField="UserName" />
        </ResourceTypes>
    </telerik:RadScheduler>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT [ID], [UserName] FROM [Users]"></asp:SqlDataSource>--%>
    </form>
</body>
</html>

and code file

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Data.SqlClient;
using System.Drawing;
using Microsoft.Office.Excel;
using  Excel= Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Collections;
 
public partial class RadSchedulerWebForm : System.Web.UI.Page
{
    string appointmentId = string.Empty;   
    string initiativeValue = string.Empty;
    int initiaveId;
    string taskValue = string.Empty;
    string assetType = string.Empty;
    string agencyValue = string.Empty;
    string statusValue = string.Empty;
    string comment = string.Empty;   
 
    string sql = string.Empty;
 
    DateTime startdDate = DateTime.Now;
    DateTime enddDate = DateTime.Now;
 
    System.Data.DataTable appointment;
    System.Data.DataTable status;
    SqlDataAdapter adapter;
    SqlConnection conn;
    SqlCommand cmd;  
 
    private List<AppointmentInfo> Appointments
    {
        get
        {
            List<AppointmentInfo> sessApts = Session["Appointments"] as List<AppointmentInfo>;
            if (sessApts == null)
            {
                sessApts = new List<AppointmentInfo>();
                Session["Appointments"] = sessApts;
            }
 
            return sessApts;
        }
    }
 
 
 
    private System.Data.DataTable dtApp
    {
        get
        {
            System.Data.DataTable sessdtApp = Session["dtApp"] as System.Data.DataTable;
            if (sessdtApp == null)
            {
                sessdtApp = new System.Data.DataTable();
                Session["Appointments"] = sessdtApp;
            }
 
            return sessdtApp;
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {          
         
    }
 
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
 
        if (!IsPostBack)
        {
            //Session.Remove("Appointments");
            //RadScheduler1.DataSource = GetAppointments();
            LoadInitiave(ddlInitiave);
             
            RadScheduler1.DataSource = GetAppointments();
        }
 
         
       // RadScheduler1.DataSource = Appointments;
        ddlInitiave.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(ddlInitiave_SelectedIndexChanged);
        btnExport.Click += new EventHandler(btnExport_Click);
        RadScheduler1.SelectedView = SchedulerViewType.TimelineView;
         
        //RadScheduler1.TimelineView.GroupBy=
    }
 
    protected  void btnExport_Click(object sender, EventArgs e)
    {
       //// throw new NotImplementedException();
       // appointment = new System.Data.DataTable();
       // appointment = GetAppointments();
 
       // //ExportToSpreadsheet(appointment, "TestExcel");
       // Excel_FromDataTable(appointment);
    }
 
    protected void ddlInitiave_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (ddlInitiave.SelectedItem.Value == "0")
        {
            RadScheduler1.DataSource = GetAppointments();
        }
        else
        {
            RadScheduler1.DataSource = GetAppointmentByInitiative(ddlInitiave.SelectedValue);
        }
    }
 
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
     {
        //To apply color on each appointments
 
        appointmentId = Convert.ToString(e.Appointment.ID);
 
        //After Inserting and appointment
        if (appointmentId == string.Empty)
        {
 
            statusValue = e.Appointment.Attributes["statusValue"];
            {
                switch (statusValue)
                {
                    case "1":  //Scheduled
                        e.Appointment.BackColor = Color.SkyBlue;
                        break;
                    case "2": //Happenned
                        e.Appointment.BackColor = Color.PeachPuff;
                        break;
                    case "3": //Didnt Happen
                        e.Appointment.BackColor = Color.Orange;
                        break;
                    default:
                        break;
                }
            }
        }
        else
        {
            //for AppointmentDataBound
            status = GetStatusByAppointmentId(appointmentId);
 
            if (status.Rows.Count > 0)
            {
                foreach (DataRow row in status.Rows)
                {
                    statusValue = row["Status"].ToString();
                    switch (statusValue)
                    {
                        case "1":  //Scheduled
                            e.Appointment.BackColor = Color.SkyBlue;
                            break;
                        case "2": //Happenned
                            e.Appointment.BackColor = Color.PeachPuff;
                            break;
                        case "3": //Didnt Happen
                            e.Appointment.BackColor = Color.Orange;
                            break;
                        default:
                            break;
                    }
 
                }
            }
        }
    }
 
    protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
        initiaveId=Convert.ToInt32(e.Appointment.Attributes["initiativeName"]);
        initiativeValue = e.Appointment.Attributes["initiativeName"];
        taskValue = e.Appointment.Attributes["task"];
        assetType = e.Appointment.Attributes["assetType"];
        agencyValue = e.Appointment.Attributes["agencyValue"];
        statusValue = e.Appointment.Attributes["statusValue"];
        comment = e.Appointment.Attributes["Comments"];
 
        InsertAppointment(e.Appointment.Subject, Convert.ToDateTime(e.Appointment.Start), Convert.ToDateTime(e.Appointment.End), initiaveId, taskValue, assetType, agencyValue, statusValue, comment);
 
    }
 
    protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
    {
        //To Update Appointment
 
        appointmentId = e.Appointment.ID.ToString();
 
        initiativeValue = e.ModifiedAppointment.Attributes["initiativeName"];
        taskValue = e.ModifiedAppointment.Attributes["task"];
        assetType = e.ModifiedAppointment.Attributes["assetType"];
        agencyValue = e.ModifiedAppointment.Attributes["agencyValue"];
        statusValue = e.ModifiedAppointment.Attributes["statusValue"];
        comment = e.ModifiedAppointment.Attributes["Comments"];
 
        if (initiativeValue == null || taskValue == null || agencyValue == null || statusValue == string.Empty || comment == string.Empty)
        {
            System.Data.DataTable dt = GetAppointmentById(appointmentId);
 
            foreach (DataRow row in dt.Rows)
            {
                initiativeValue = row["InitiativeId"].ToString();
                taskValue = row["TaskId"].ToString();
                assetType = row["AssetType"].ToString();
                agencyValue = row["Agency"].ToString();
                statusValue = row["Status"].ToString();
                comment = row["Description"].ToString();
            }
        }
 
        UpdateAppointment(appointmentId, e.ModifiedAppointment.Subject, Convert.ToDateTime(e.ModifiedAppointment.Start), Convert.ToDateTime(e.ModifiedAppointment.End), initiativeValue, taskValue,assetType,agencyValue, statusValue, comment);
 
        //AppointmentInfo ai = FindById(e.ModifiedAppointment.ID);
        //ai.CopyInfo(e.ModifiedAppointment);
 
    }
 
    protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e)
    {
        //To Delete Appointment
 
        // Appointments.Remove(FindById(e.Appointment.ID));
        appointmentId = e.Appointment.ID.ToString();
        DeleteAppointment(appointmentId);
    }
 
    private AppointmentInfo FindById(object ID)
    {
        foreach (AppointmentInfo ai in Appointments)
        {
            if (ai.ID.Equals(ID))
            {
                return ai;
            }
        }
 
        return null;
    }
 
    protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
    {
        RadScheduler scheduler = (RadScheduler)sender;
 
        //AdvanceInsert Mode
        if (e.Container.Mode == SchedulerFormMode.AdvancedInsert)
        {
 
 
            RadComboBox ddlInitiaveName = (RadComboBox)e.Container.FindControl("ddlInitiaveName");
            LoadInitiave(ddlInitiaveName);
 
            RadComboBox ddlTask = (RadComboBox)e.Container.FindControl("ddlTask");
            LoadTask(ddlTask);
 
            RadComboBox ddlAssetType = (RadComboBox)e.Container.FindControl("ddlAssetType");
            LoadAssetType(ddlAssetType);
 
            RadTextBox subjectBox = (RadTextBox)e.Container.FindControl("TitleTextBox");
            subjectBox.Text = e.Appointment.Subject;
 
            RadComboBox ddlAgency = (RadComboBox)e.Container.FindControl("ddlAgency");
            ddlAgency.LoadContentFile("~/App_Data/AgencyItems.xml");
 
            RadDateTimePicker startInput = (RadDateTimePicker)e.Container.FindControl("StartInput");
            startInput.DateInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;                                   
            startInput.SelectedDate = RadScheduler1.DisplayToUtc(e.Appointment.Start);
 
            RadDateTimePicker endInput = (RadDateTimePicker)e.Container.FindControl("EndInput");
            endInput.DateInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;
            endInput.SelectedDate = RadScheduler1.DisplayToUtc(e.Appointment.End);
 
            RadComboBox ddlStatus = (RadComboBox)e.Container.FindControl("ddlStatus");
            ddlStatus.LoadContentFile("~/App_Data/StatusItems.xml");
 
        }
 
 
 
        //AdvanceEdit Mode
        if (e.Container.Mode == SchedulerFormMode.AdvancedEdit)
        {
            appointmentId = e.Appointment.ID.ToString();
 
            if (appointmentId != string.Empty)
            {
                System.Data.DataTable dt = GetAppointmentById(appointmentId);
 
                foreach (DataRow row in dt.Rows)
                {
                    initiativeValue = row["InitiativeId"].ToString();
                    taskValue = row["TaskId"].ToString();
                    assetType = row["AssetType"].ToString();
                    agencyValue = row["Agency"].ToString();
                    startdDate = Convert.ToDateTime(row["Start"].ToString());
                    enddDate = Convert.ToDateTime(row["End"].ToString());
                    statusValue = row["Status"].ToString();
                    comment = row["Description"].ToString();
                }
 
                RadComboBox ddlInitiaveName = (RadComboBox)e.Container.FindControl("ddlInitiaveName");
                LoadInitiave(ddlInitiaveName);
                ddlInitiaveName.SelectedValue = initiativeValue;
 
                RadComboBox ddlTask = (RadComboBox)e.Container.FindControl("ddlTask");
                LoadTask(ddlTask);
                ddlTask.SelectedValue = taskValue;
 
                RadComboBox ddlAssetType = (RadComboBox)e.Container.FindControl("ddlAssetType");
                LoadAssetType(ddlAssetType);
                ddlAssetType.SelectedValue = assetType;
 
 
                RadComboBox ddlAgency = (RadComboBox)e.Container.FindControl("ddlAgency");
                ddlAgency.LoadContentFile("~/App_Data/AgencyItems.xml");
                ddlAgency.SelectedValue = agencyValue;
 
                RadDateTimePicker startInput = (RadDateTimePicker)e.Container.FindControl("StartInput");               
                startInput.DateInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;                             
                startInput.SelectedDate = startdDate;
 
                RadDateTimePicker endInput = (RadDateTimePicker)e.Container.FindControl("EndInput");
                endInput.DateInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;
                endInput.SelectedDate = enddDate;
 
                RadComboBox ddlStatus = (RadComboBox)e.Container.FindControl("ddlStatus");
                ddlStatus.LoadContentFile("~/App_Data/StatusItems.xml");
                ddlStatus.SelectedValue = statusValue;
 
                RadTextBox commentsBox = (RadTextBox)e.Container.FindControl("CommentsTextBox");
                commentsBox.Text = comment;
 
            }
 
        }
    }
 
    protected System.Data.DataTable GetAppointments()
    {
        appointment = new System.Data.DataTable();
 
        conn = new SqlConnection(GetConnectionString());
        adapter = new SqlDataAdapter("SELECT ID,Subject,Start,[End],InitiativeId,TaskId,AssetType,Agency,Status,Description,RecurrenceRule,RecurrenceParentId FROM Appointments order by ID", conn);
        adapter.Fill(appointment);
 
        return appointment;
    }
 
    //protected System.Data.DataTable GetAppointments()
    //{
    //    appointment = new System.Data.DataTable();
 
    //    conn = new SqlConnection(GetConnectionString());
    //    adapter = new SqlDataAdapter("SELECT from Initiavtiv", conn);
    //    adapter.Fill(appointment);
 
    //    return appointment;
    //}
 
    protected System.Data.DataTable GetAppointmentById(string appointmentid)
    {
        appointment = new System.Data.DataTable();
 
        conn = new SqlConnection(GetConnectionString());
        adapter = new SqlDataAdapter("SELECT Subject,Start,[End],InitiativeId,TaskId,AssetType,Agency,Status,Description,RecurrenceRule,RecurrenceParentId FROM Appointments WHERE ID=" + appointmentid + "", conn);
        adapter.Fill(appointment);
 
        return appointment;
    }
 
    protected System.Data.DataTable GetStatusByAppointmentId(string appointmentid)
    {
        status = new System.Data.DataTable();
 
        conn = new SqlConnection(GetConnectionString());
        adapter = new SqlDataAdapter("SELECT Status FROM Appointments WHERE ID=" + appointmentid + "", conn);
        adapter.Fill(status);
 
        return status;
    }
 
    protected System.Data.DataTable GetAppointmentByInitiative(string Initiative)
    {
        appointment = new System.Data.DataTable();
 
        conn = new SqlConnection(GetConnectionString());
        adapter = new SqlDataAdapter("SELECT ID,Subject,Start,[End],TaskId,AssetType,Agency,Status,Description,RecurrenceRule,RecurrenceParentId FROM Appointments WHERE InitiativeId=" + Initiative + "", conn);
        adapter.Fill(appointment);
 
        return appointment;
    }   
 
    protected void LoadInitiave(RadComboBox ddlinitiavename)
    {
        try
        {
            conn = new SqlConnection(GetConnectionString());
 
            adapter = new SqlDataAdapter("SELECT InitiativeName,ID FROM [Initiatives] order by ID", conn);
            System.Data.DataTable dt = new System.Data.DataTable();
            adapter.Fill(dt);
            ddlinitiavename.DataTextField = "InitiativeName";
            ddlinitiavename.DataValueField = "ID";
            ddlinitiavename.DataSource = dt;
 
            RadComboBoxItem firstitem = new RadComboBoxItem();
            firstitem.Text = " --- Select  Initiative --- ";
            firstitem.Value = "0";
            ddlinitiavename.Items.Add(firstitem);
 
            foreach (DataRow row in dt.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();               
                item.Text = row["InitiativeName"].ToString();
                item.Value = row["ID"].ToString();
                ddlinitiavename.Items.Add(item);              
            }
        }
        catch (Exception ex)
        { }
        finally
        {
            conn.Close();
        }
    }
 
    protected void LoadTask(RadComboBox ddltask)
    {
        try
        {
            conn = new SqlConnection(GetConnectionString());
 
            adapter = new SqlDataAdapter("SELECT Title,ID FROM [Master Task List] order by ID", conn);
            System.Data.DataTable dt = new System.Data.DataTable();
            adapter.Fill(dt);
            ddltask.DataTextField = "Title";
            ddltask.DataValueField = "ID";
            ddltask.DataSource = dt;
 
            foreach (DataRow row in dt.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();
                item.Text = row["Title"].ToString();
                item.Value = row["ID"].ToString();
                ddltask.Items.Add(item);
            }
        }
        catch (Exception ex)
        { }
        finally
        {
            conn.Close();
        }
 
 
    }
 
    protected void LoadAssetType(RadComboBox ddlassettype)
    {
        try
        {
            conn = new SqlConnection(GetConnectionString());
 
            adapter = new SqlDataAdapter("SELECT ID,AssetType FROM AssetType order by ID", conn);
            System.Data.DataTable dt = new System.Data.DataTable();
            adapter.Fill(dt);
            ddlassettype.DataTextField = "AssetType";
            ddlassettype.DataValueField = "ID";
            ddlassettype.DataSource = dt;
 
            foreach (DataRow row in dt.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();
                item.Text = row["AssetType"].ToString();
                item.Value = row["ID"].ToString();
                ddlassettype.Items.Add(item);
            }
        }
        catch (Exception ex)
        { }
        finally
        {
            conn.Close();
        }
 
 
    }
 
    public string GetConnectionString()
    {
        return System.Configuration.ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString;
    }
 
    private void InsertAppointment(string subject, DateTime start, DateTime end, int initiative, string task,string assettype, string agency, string status, string comments)
    {
        conn = new SqlConnection(GetConnectionString());
        sql = "INSERT INTO Appointments (Subject,Start,[End],InitiativeId,TaskId,AssetType,Agency,Status,Description) VALUES (@subject,@start,@end,@initiative,@task,@assettype,@agency,@status,@comments)";
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            //cmd.Parameters.AddWithValue("@id",Guid.NewGuid().ToString() );
            cmd.Parameters.AddWithValue("@subject", subject);
            cmd.Parameters.AddWithValue("@start", start);
            cmd.Parameters.AddWithValue("@end", end);
            cmd.Parameters.AddWithValue("@initiative", initiative);
            cmd.Parameters.AddWithValue("@task", task);
            cmd.Parameters.AddWithValue("@assettype", assettype);
            cmd.Parameters.AddWithValue("@agency", agency);
            cmd.Parameters.AddWithValue("@status", status);
            cmd.Parameters.AddWithValue("@comments", comments);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
 
        }
        finally
        {
            conn.Close();
        }
    }
 
    private void UpdateAppointment(string appointmentId, string subject, DateTime start, DateTime end, string initiative, string task,string assettype, string agency, string status, string comments)
    {
        conn = new SqlConnection(GetConnectionString());
        sql = "UPDATE Appointments SET Subject=@subject,Start=@start,[End]=@end,InitiativeId=@initiative,TaskId=@task,AssetType=@assettype,Agency=@agency,Status=@status,Description=@comments WHERE ID=" + appointmentId + "";
        try
        {
            conn.Open();
            cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@subject", subject);
            cmd.Parameters.AddWithValue("@start", start);
            cmd.Parameters.AddWithValue("@end", end);
            cmd.Parameters.AddWithValue("@initiative", initiative);
            cmd.Parameters.AddWithValue("@task", task);
            cmd.Parameters.AddWithValue("@assettype", assettype);
            cmd.Parameters.AddWithValue("@agency", agency);
            cmd.Parameters.AddWithValue("@status", status);
            cmd.Parameters.AddWithValue("@comments", comments);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
 
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Update Error:";
            msg += ex.Message;
            throw new Exception(msg);
 
        }
        finally
        {
            conn.Close();
        }
 
    }
 
    private void DeleteAppointment(string appointmentId)
    {
        conn = new SqlConnection(GetConnectionString());
        sql = "DELETE FROM Appointments WHERE ID=@id";
        try
        {
            conn.Open();
            cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@id", appointmentId);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Delete Error:";
            msg += ex.Message;
            throw new Exception(msg);
 
        }
        finally
        {
            conn.Close();
        }
    }
 
    public static void ExportToSpreadsheet(System.Data.DataTable table, string name)
    {
        HttpContext context = HttpContext.Current;
        context.Response.Clear();
        foreach (DataColumn column in table.Columns)
        {
            context.Response.Write(column.ColumnName + ";");
        }
        context.Response.Write(Environment.NewLine);
        foreach (DataRow row in table.Rows)
        {
            for (int i = 0; i < table.Columns.Count; i++)
            {
                context.Response.Write(row[i].ToString().Replace(";", string.Empty) + ";");
            }
            context.Response.Write(Environment.NewLine);
        }
        context.Response.ContentType = "text/csv";
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".csv");
        context.Response.End();
    }
 
    // TO USE:
    // 1) include COM reference to Microsoft Excel Object library
    // add namespace...
     //using Excel = Microsoft.Office.Interop.Excel;   
 
    private static void Excel_FromDataTable(System.Data.DataTable dt)
    {
         
         
        // Create an Excel object and add workbook...
        Excel.ApplicationClass excel = new Excel.ApplicationClass();
        Excel.Workbook workbook = excel.Application.Workbooks.Add(true); // true for object template???
 
        // Add column headings...
        int iCol = 0;
        foreach (DataColumn c in dt.Columns)
        {
            iCol++;
            excel.Cells[1, iCol] = c.ColumnName;
        }
        // for each row of data...
        int iRow = 0;
        foreach (DataRow r in dt.Rows)
        {
            iRow++;
 
            // add each row's cell data...
            iCol = 0;
            foreach (DataColumn c in dt.Columns)
            {
                iCol++;
                excel.Cells[iRow + 1, iCol] = r[c.ColumnName];
            }
        }
 
        // Global missing reference for objects we are not defining...
        object missing = System.Reflection.Missing.Value;
 
        // If wanting to Save the workbook...
        workbook.SaveAs("Scheduler.xls",
            Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
            false, false, Excel.XlSaveAsAccessMode.xlNoChange,
            missing, missing, missing, missing, missing);
 
        // If wanting to make Excel visible and activate the worksheet...
        excel.Visible = true;
        Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
        ((Excel._Worksheet)worksheet).Activate();
 
        // If wanting excel to shutdown...
        ((Excel._Application)excel).Quit();
    }
 
 
}

Kinldy suggest me where i made mistake ?

If i can solve it by adding Resoueces then how can i do that with Resources ?

Reply me ASAP.

Thanks a lot,
Nirav

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 22 Mar 2012, 05:59 PM
Hi Nirav,

Take a look at the following online resources:
Resources Grouping.
Working with resources.
Custom Attributes.

If still having troubles, I suggest to open a support ticket where a sample project can be attached so we would be able to troubleshoot the problem you experience locally.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Scheduler
Asked by
Nirav
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or