Hi
I am binding the object datasorce at runtime to radschedular and also I have validate overriding of appointment
help me in which page event I should bind data so data is available for data binding
My problem is if I add data in oninit the schedular not get refreshed after insert data and if I bind data in onprerender the validation not working
I am binding the object datasorce at runtime to radschedular and also I have validate overriding of appointment
help me in which page event I should bind data so data is available for data binding
My problem is if I add data in oninit the schedular not get refreshed after insert data and if I bind data in onprerender the validation not working
<telerik:RadScheduler runat="server" ID="EventScheduler" Skin="Office2010Silver" EnableEmbeddedSkins="false" ShowViewTabs="False" SelectedView="TimelineView" StartEditingInAdvancedForm="true" StartInsertingInAdvancedForm="true" CustomAttributeNames="BookedBy,HostEmpNo,HostName,BookedByName" AppointmentStyleMode="Default" OverflowBehavior="Expand" RowHeaderWidth="230" RowHeight="48" EnableExactTimeRendering="True" ShowFooter="False" OnClientAppointmentInserting="AppointmentInserting" OnClientAppointmentMoveEnd="AppointmentMoveEnd" OnClientAppointmentResizing="AppointmentResizing" OnClientTimeSlotClick="InsertAppointment" OnClientFormCreated="SchedulerFormCreated" OnAppointmentDataBound="EventScheduler_AppointementDataBound" OnResourceHeaderCreated="EventScheduler_ResourceHeaderCreated" OnNavigationCommand="EventScheduler_NavigationCommand" OnNavigationComplete="EventScheduler_NavigationComplete" OnPreRender="EventScheduler_PreRender" OnTimeSlotCreated="EventScheduler_TimeSlotCreated" OnAppointmentCreated="EventScheduler_AppointmentCreated" OnAppointmentInsert="EventScheduler_AppointmentInsert" OnAppointmentUpdate="EventScheduler_AppointmentUpdate" OnAppointmentDelete="EventScheduler_AppointmentDelete" OnRecurrenceExceptionCreated="EventScheduler_RecurrenceExceptionCreated"> <AdvancedForm Modal="True" EnableCustomAttributeEditing="True" /> <TimeSlotContextMenuSettings EnableDefault="True" /> <TimeSlotContextMenus> <telerik:RadSchedulerContextMenu runat="server" ID="SchedulerTimeSlotContextMenu"> <Items> <telerik:RadMenuItem Text="New Event" ImageUrl="Images/EventNew.gif" Value="CommandAddAppointment"> </telerik:RadMenuItem> <telerik:RadMenuItem Text="New Recurring Event" ImageUrl="Images/EventRecurring.gif" Value="CommandAddRecurringAppointment"> </telerik:RadMenuItem> </Items> </telerik:RadSchedulerContextMenu> </TimeSlotContextMenus> <TimelineView GroupBy="Room" GroupingDirection="Vertical" TimeLabelSpan="1" ColumnHeaderDateFormat="HH:mm" /> <ResourceTypes> <telerik:ResourceType Name="Room" KeyField="ResourceID" TextField="ResourceName" ForeignKeyField="ResourceID" /> </ResourceTypes> <ResourceHeaderTemplate> <div style="text-align: left; padding: 5px 0 0 5px;"> <asp:Label ID="lblRoom" runat="server" ForeColor="DarkBlue" Text='<%# Eval("Text") %>' /> <br /> <br /> <div class="floatingmandiv"> <asp:HyperLink ID="hlImgRoom" runat="server" ClientIDMode="Static" NavigateUrl='<%# String.Concat(@"~/Pages/Handlers/ImgHandler.ashx?key=",Eval("Key")) %>'> <asp:Image ID="imgRoom" runat="server" CssClass="zoomCursor" ImageUrl='<%# String.Concat(@"~/Pages/Handlers/ImgHandler.ashx?key=",Eval("Key")) %>' /> </asp:HyperLink> </div> <asp:Label ID="lblCapacity" runat="server" Visible="False" /> <asp:Repeater runat="server" ID="rptABC"> <ItemTemplate> <div class="floating"> <asp:Image ID="imgProjector" runat="server" ToolTip='<%# Eval("RaRoomName") %>' Height="30" Width="30" ImageUrl='<%# string.Format("../Pages/Handlers/IconHandler.ashx?key={0}",Eval("RaId"))%>' onmouseover='showToolTip(this);' /> </div> </ItemTemplate> </asp:Repeater> <%-- <asp:Image ID="imgProjector" runat="server" Height="32" Width="32" Visible="False" ImageUrl="../Pages/Handlers/IconHandler.ashx?key=1" onmouseover='showToolTip(this);' /> <asp:Image ID="imgBoard" runat="server" Height="32" Width="32" Visible="False" ImageUrl="../Pages/Handlers/IconHandler.ashx?key=3" onmouseover='showToolTip(this);' /> <asp:Image ID="imgCapacity" runat="server" Height="32" Width="32" Visible="False" ImageUrl="../Pages/Handlers/IconHandler.ashx?key=2" onmouseover='showToolTip(this);' /> <asp:Label ID="lblCapacity" runat="server" Visible="False" />--%> </div> </ResourceHeaderTemplate> <AdvancedInsertTemplate> <scheduler:AdvancedForm runat="server" ID="AdvancedFormInsert1" Mode="Insert" Subject='<%# Bind("Subject") %>' Start='<%# Bind("Start") %>' End='<%# Bind("End") %>' RecurrenceRuleText='<%# Bind("RecurrenceRule") %>' Booker='<%# Bind("BookedBy") %>' HostEmp='<%# Bind("HostEmpNo") %>' /> </AdvancedInsertTemplate> <AdvancedEditTemplate> <scheduler:AdvancedForm runat="server" ID="AdvancedFormEdit1" Mode="Edit" Subject='<%# Bind("Subject") %>' Start='<%# Bind("Start") %>' End='<%# Bind("End") %>' RecurrenceRuleText='<%# Bind("RecurrenceRule") %>' Booker='<%# Bind("BookedBy") %>' HostEmp='<%# Bind("HostEmpNo") %>' /> </AdvancedEditTemplate> </telerik:RadScheduler>#region Page Events protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); BindEventSchedular(); } protected override void OnInit(EventArgs e) { base.OnInit(e); BindEventSchedular(); } protected override void OnPreLoad(EventArgs e) { //Utility.SetSqlDSQueries(LocationDS, RoomDS, EventsDS); if (!IsPostBack) { Session["Locationstring"] = null; BindLocation(); } //BindEventSchedular(); if (IsPostBack) return; Utility.RefreshContext(); Utility.SetTooltips(); } private void BindEventSchedular() { //ResourceEventCollection oResourceEventColl = ResourceEvent.LoadList(); //if (oResourceEventColl == null) // oResourceEventColl = new ResourceEventCollection(); string sLocations = ""; if (Session["Locationstring"] != null) { sLocations = Session["Locationstring"].ToString(); } else { sLocations = ""; } ESSLib.Data.DataObjects.ResourceCollection oResourceColl = ESSLib.Data.DataObjects.Resource.ResourcesByLocation(sLocations); if (oResourceColl != null) { List<ResourceEvent> oResourceEventColl = ResourceEvent.LoadList().ToList(); if (oResourceEventColl == null) oResourceEventColl = new System.Collections.Generic.List<ResourceEvent>(); else { oResourceEventColl = (from oresourceevent in oResourceEventColl join oresource in oResourceColl on oresourceevent.ResourceID equals oresource.ResourceID select oresourceevent).ToList(); } EventScheduler.DataSource = oResourceEventColl; EventScheduler.DataKeyField = "ResourceEventHeadID"; EventScheduler.DataSubjectField = "ResourceEvent"; EventScheduler.DataStartField = "EventStartDate"; EventScheduler.DataEndField = "EventEndDate"; EventScheduler.DataRecurrenceField = "RecurrenceRule"; EventScheduler.DataRecurrenceParentKeyField = "RecurrenceParentID"; EventScheduler.ResourceTypes[0].DataSource = oResourceColl; EventScheduler.DataBind(); } } private void BindLocation() { LocationCollection oLocationColl = Location.LoadList(); ESSLib.Data.DataObjects.ResourceCollection oResourceColl = ESSLib.Data.DataObjects.Resource.LoadList(); if (oLocationColl != null && oResourceColl != null) { List<Location> oLocation = (from olocation in oLocationColl join oresourcecoll in oResourceColl on olocation.LocationCode equals oresourcecoll.LocationCode select olocation).ToList(); chkLocationList.DataSource = oLocation; chkLocationList.DataTextField = "LocationDesc"; chkLocationList.DataValueField = "LocationCode"; chkLocationList.DataBind(); } } protected void Page_Load(object sender, EventArgs e) { #region Set logged in user from web.config // Validate user string userRole; Employee oEmployee = new Employee(Session["EmpNo"].ToString()); if (oEmployee.IsExists) { userRole = oEmployee.ProfileCode == 1 ? "Admin" : "User"; Session["User"] = new List<string> { userRole, oEmployee.EmpNo }; } else Session["User"] = Utility.LoggedUserRole = Utility.LoggedUserEmp = null; // Save logged in user information if (Session["User"] == null) return; var data = Session["User"] as List<string>; if (data == null) return; Utility.LoggedUserRole = data[0]; Utility.LoggedUserEmp = data[1]; #endregion if (IsPostBack) return; Utility.SetTimeLineAttributes(EventScheduler, hfSchedulerDate); } protected void Page_LoadComplete(object sender, EventArgs e) { if (Utility.Resources != null) Utility.Resources.Clear(); } #endregion #region Scheduler Events protected void EventScheduler_AppointementDataBound(object sender, SchedulerEventArgs e) { //BindEventSchedular(); Utility.SetAppointmentAttributes(e); } protected void EventScheduler_ResourceHeaderCreated(object sender, ResourceHeaderCreatedEventArgs e) { Utility.SetHeaderAttributes(e); } protected void EventScheduler_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e) { var aptStartTime = e.TimeSlot.Start.TimeOfDay; var aptEndTime = e.TimeSlot.End.TimeOfDay; //Get Open and Close Time if (Utility.Resources != null && !Utility.Resources.Contains(e.TimeSlot.Resource.Text)) { Utility.Resources.Add(e.TimeSlot.Resource.Text); Utility.GetHours(e.TimeSlot.Resource.Text, out _resStartTime, out _resEndTime); } else if (Utility.Resources == null) { Utility.Resources = new List<string> { e.TimeSlot.Resource.Text }; Utility.GetHours(e.TimeSlot.Resource.Text, out _resStartTime, out _resEndTime); } if (Utility.IsBlockedTimeSlot(aptStartTime, aptEndTime, _resStartTime, _resEndTime)) { e.TimeSlot.CssClass = "Disabled"; } } protected void EventScheduler_NavigationCommand(object sender, SchedulerNavigationCommandEventArgs e) { switch (e.Command) { case SchedulerNavigationCommand.NavigateToPreviousPeriod: //EventScheduler.SelectedDate = Utility.GetDate(Utility.Commands.Prev, EventScheduler.SelectedDate); break; case SchedulerNavigationCommand.NavigateToNextPeriod: EventScheduler.SelectedDate = Utility.GetDate(Utility.Commands.Next, EventScheduler.SelectedDate); break; } } protected void EventScheduler_NavigationComplete(object sender, SchedulerNavigationCompleteEventArgs e) { if (EventScheduler.SelectedView != SchedulerViewType.TimelineView) return; Utility.SetTimeLineAttributes(EventScheduler, hfSchedulerDate); } protected void EventScheduler_PreRender(object sender, EventArgs e) { // Set Scheduler width as per timeslots var slotsWidth = Convert.ToInt32(Utility.NumberOfSlots * 51); const int rowHeaderWidth = 230; EventScheduler.Width = Unit.Pixel(slotsWidth + rowHeaderWidth); // Hide location panel if no resources var resources = from c in Utility.EssResources select c; pnlLocations.Visible = resources.Any(); } #endregion #region Appointement Insert, Update & Delete protected void EventScheduler_AppointmentInsert(object sender, AppointmentInsertEventArgs e) { if (Session["User"] != null) { var aptStartTime = e.Appointment.Start.TimeOfDay; var aptEndTime = e.Appointment.End.TimeOfDay; var resource = e.Appointment.Resources.GetResourceByType("Room"); bool isOk = true; // Check if blocked timeslot Utility.GetHours(resource.Text, out _resStartTime, out _resEndTime); if (Utility.IsBlockedTimeSlot(aptStartTime, aptEndTime, _resStartTime, _resEndTime)) { e.Cancel = true; isOk = false; ShowErrorMessage("Creating events in blocked timeslot is not allowed."); } // Check if there is alreay an appointment if (Utility.ExceedsLimit(e.Appointment, EventScheduler)) { e.Cancel = true; isOk = false; ShowErrorMessage("Creating events in occupied timeslot is not allowed."); } //string s = ((RadComboBox)EventScheduler.FindControl("ResHostEmp")).SelectedValue;\\ if (isOk) { int iRecurrenceParentID; if (e.Appointment.RecurrenceState == RecurrenceState.NotRecurring) iRecurrenceParentID = -1; else iRecurrenceParentID = Convert.ToInt32(e.Appointment.RecurrenceParentID); Utility.InsertAppointment(e.Appointment.Subject, e.Appointment.Start, e.Appointment.End, Convert.ToInt32(resource.Key), Session["HostNo"].ToString(), Session["EmpNo"].ToString(), e.Appointment.RecurrenceRule.ToString(), iRecurrenceParentID); Session["HostNo"] = null; EventScheduler.Rebind(); } else { e.Cancel = true; } } else { e.Cancel = true; ShowErrorMessage("Only logged in user can create events."); } } protected void EventScheduler_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e) { if (Session["User"] != null) { var aptStartTime = e.Appointment.Start.TimeOfDay; var aptEndTime = e.Appointment.End.TimeOfDay; var resource = e.Appointment.Resources.GetResourceByType("Room"); bool isOk = true; // Do not allow for blocked timeslot to anyone Utility.GetHours(resource.Text, out _resStartTime, out _resEndTime); if (Utility.IsBlockedTimeSlot(aptStartTime, aptEndTime, _resStartTime, _resEndTime)) { e.Cancel = true; isOk = false; ShowErrorMessage("Updating events in blocked timeslot is not allowed."); } // If it is not user's created event if (Utility.LoggedUserRole == "User" && !e.Appointment.Attributes["BookedBy"].Equals(Utility.LoggedUserEmp)) { e.Cancel = true; isOk = false; ShowErrorMessage("You cannot modify other user's created events."); } // If appointment overlaps if (Utility.AppointmentsOverlap(e.ModifiedAppointment, EventScheduler)) { e.Cancel = true; isOk = false; ShowErrorMessage("Updating events in occupied timeslot is not allowed."); } if (isOk) { int iRecurrenceParentID; if (e.ModifiedAppointment.RecurrenceState == RecurrenceState.NotRecurring) iRecurrenceParentID = -1; else iRecurrenceParentID = Convert.ToInt32(e.ModifiedAppointment.RecurrenceParentID); if (Session["HostNo"] == null) { Session["HostNo"] = e.Appointment.Attributes["HostEmpNo"]; } Utility.UpdateAppointment(Convert.ToInt32(e.Appointment.ID), e.ModifiedAppointment.Subject, e.ModifiedAppointment.Start, e.ModifiedAppointment.End, Convert.ToInt32(resource.Key), Session["HostNo"].ToString(), Session["EmpNo"].ToString(), e.ModifiedAppointment.RecurrenceRule.ToString(), iRecurrenceParentID); EventScheduler.Rebind(); Session["HostNo"] = null; } } else { e.Cancel = true; ShowErrorMessage("Only logged in user can modify events."); } } protected void EventScheduler_AppointmentDelete(object sender, AppointmentDeleteEventArgs e) { if (Session["User"] != null) { if (Utility.LoggedUserRole == "User" && !e.Appointment.Attributes["BookedBy"].Equals(Utility.LoggedUserEmp)) { e.Cancel = true; ShowErrorMessage("You cannot delete other user's created events."); } Utility.DeleteAppointment(Convert.ToInt32(e.Appointment.ID)); EventScheduler.Rebind(); } else { e.Cancel = true; ShowErrorMessage("Only logged in user can delete events."); } } protected void EventScheduler_RecurrenceExceptionCreated(object sender, RecurrenceExceptionCreatedEventArgs e) { if (!Utility.AppointmentsOverlap(e.ExceptionAppointment, EventScheduler)) return; e.Cancel = true; ShowErrorMessage("Exception occured. You are trying disabled actions."); } protected void EventScheduler_AppointmentCommand(object sender, AppointmentCommandEventArgs e) { Control SchedulerAdvancedForm; switch (e.CommandName.ToLower()) { case "insert": SchedulerAdvancedForm = e.Container.FindControl("AdvancedFormInsert1"); break; case "update": SchedulerAdvancedForm = e.Container.FindControl("AdvancedFormEdit1"); break; default: SchedulerAdvancedForm = e.Container.FindControl("AdvancedFormInsert1"); break; } if (SchedulerAdvancedForm != null) { e.Container.Appointment.Attributes["HostEmpNo"] = ((RadComboBox)SchedulerAdvancedForm.FindControl("ResHostEmp")).SelectedValue; } } #endregion #region Show Tooltip in EventScheduler protected void EventScheduler_AppointmentCreated(object sender, AppointmentCreatedEventArgs e) { if (!e.Appointment.Visible || IsAppointmentRegisteredForTooltip(e.Appointment)) return; var id = e.Appointment.ID.ToString(); foreach (var domElementID in e.Appointment.DomElements) { EventToolTipManager.TargetControls.Add(domElementID, id, true); } } private bool IsAppointmentRegisteredForTooltip(Appointment apt) { return EventToolTipManager.TargetControls.Cast<ToolTipTargetControl>().Any(targetControl => apt.DomElements.Contains(targetControl.TargetControlID)); } protected void EventToolTipManager_AjaxUpdate(object sender, ToolTipUpdateEventArgs e) { var appointment = EventScheduler.Appointments.FirstOrDefault(apt => apt.ID.ToString().Equals(e.Value)); if (appointment == null) return; var toolTip = (EventToolTip)LoadControl("~/Pages/UserControls/EventToolTip.ascx"); toolTip.TargetAppointment = appointment; e.UpdatePanel.ContentTemplateContainer.Controls.Add(toolTip); } #endregion #region Location and Filter protected void chkLocationList_DataBound(object sender, EventArgs e) { string sLocationstring = ""; for (var i = 0; i < chkLocationList.Items.Count; i++) { if (sLocationstring == "") sLocationstring = chkLocationList.Items[i].Value; else sLocationstring = sLocationstring + "," + chkLocationList.Items[i].Value; Session["Locationstring"] = sLocationstring; chkLocationList.Items[i].Selected = true; chkLocationList.Items[i].Text = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(chkLocationList.Items[i].Text.ToLower()); } } protected void chkLocationList_SelectedIndexChanged(object sender, EventArgs e) { //RoomDS.SelectCommand = Utility.FilterQuery(chkLocationList); //RoomDS.DataBind(); CheckBoxList ocheckboxlist = ((CheckBoxList)sender); IEnumerable<string> CheckedItems = ocheckboxlist.Items.Cast<ListItem>() .Where(i => i.Selected) .Select(o => o.Value); string sLocationstring = ""; if (CheckedItems.Count() > 0) { foreach (string s in CheckedItems) { if (sLocationstring == "") sLocationstring = s; else sLocationstring = sLocationstring + "," + s; } } Session["Locationstring"] = sLocationstring; //EventScheduler.Rebind(); } #endregion /// <summary> /// Show message to users for insert or update events in Scheduler from Advanced Form. /// </summary> /// <param name="message">Message to show to user.</param> private void ShowErrorMessage(string message) { Label1.Text = message; System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, GetType(), "LabelUpdated", "$telerik.$('.lblError').show().animate({ opacity: 0.9 }, 3000).fadeOut('slow');", true); }