Hi,
I'm using AppointmentDataBound to apply my own cssClasses to scheduler appointments based on their type, status and colour. The type, status and colour are fields I store in the appointments record in my SQL table.
This all works really well and I get icons based on the appointment type and colours based on their status etc...
My problem occurs after I insert a new appointment. I get an error 'object variable or with block variable not set' in the AppointmentDataBound code. I think this is because the dataitem is not available at this point.
This is really stumping me and I just can't seem to get around it. Here's the code :-
Here's the Insert code which works everytime
After the insert code runs the databound code is called again and any reference to e.appointment.dataitem or even e.appointment.id returns the 'object variable or with block variable not set' error.
Thanks for looking
Jase
I'm using AppointmentDataBound to apply my own cssClasses to scheduler appointments based on their type, status and colour. The type, status and colour are fields I store in the appointments record in my SQL table.
This all works really well and I get icons based on the appointment type and colours based on their status etc...
My problem occurs after I insert a new appointment. I get an error 'object variable or with block variable not set' in the AppointmentDataBound code. I think this is because the dataitem is not available at this point.
This is really stumping me and I just can't seem to get around it. Here's the code :-
| Protected Sub Calendar_AppointmentDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerEventArgs) Handles Calendar.AppointmentDataBound |
| 'Grab details about the appointments appearance |
| Dim apptComputer As String = e.Appointment.DataItem("computer_name").ToString |
| Dim apptProject As String = e.Appointment.DataItem("project_name").ToString |
| Dim apptRelease As String = e.Appointment.DataItem("release_name").ToString |
| Dim apptType As Integer = e.Appointment.DataItem("appointment_type").ToString |
| Dim apptColour As String = "White" |
| Dim apptStatus As Integer = e.Appointment.DataItem("Status").ToString |
| Dim strStatus As String = "Scheduled" |
| Dim strCSSClass As String = "rsCategoryBlue" |
| e.Appointment.Subject = "Project: " & apptProject & Chr(13) & "Release: " & apptRelease & Chr(13) & "Computer: " & apptComputer |
| 'Grab the appointment colour if it is assigned if not then |
| 'leave the setting as white (generic). |
| If e.Appointment.DataItem("colour").ToString() <> "" Then |
| apptColour = e.Appointment.DataItem("colour").ToString() |
| End If |
| 'apptStatus dictates the text colour of the appointment. |
| '1 - Scheduled = Blue |
| '2 - Failed = Red |
| '3 - Passed = Green |
| Select Case apptStatus |
| Case 1 'Scheduled |
| strStatus = "Scheduled" |
| Case 2 'Failed |
| strStatus = "Failed" |
| Case 3 'Passed |
| strStatus = "Passed" |
| End Select |
| 'apptColour dictates the background colour of the appointment |
| 'apptType dictates the icon displayed in the top left corner of the appointment |
| Select Case apptType |
| Case 1 'Generic Appointment |
| Case 2 'QualityControl |
| strCSSClass = "Quality_" & apptColour & "_" & strStatus & "_AppointmentStyle" |
| Case 3 'CompatibilityCheck |
| strCSSClass = "Compatible_" & apptColour & "_" & strStatus & "_AppointmentStyle" |
| Case 4 'PackageApp |
| strCSSClass = "Package_" & apptColour & "_" & strStatus & "_AppointmentStyle" |
| Case 5 'Release |
| strCSSClass = "Release_" & apptColour & "_" & strStatus & "_AppointmentStyle" |
| End Select |
| e.Appointment.CssClass = strCSSClass |
| End Sub |
Here's the Insert code which works everytime
| Protected Sub Calendar_OnAppointmentInsert(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerCancelEventArgs) Handles Calendar.AppointmentInsert |
| Dim sdsProjectAppointments As New SqlDataSource |
| Dim strConnection As String = ConfigurationManager.ConnectionStrings("RR3ConnectionString").ConnectionString |
| Dim myRecurrenceParentID As String = "" |
| 'Check to see if the appointment has a RecurrenceParentID |
| 'If so then set the variable if not then leave as "". Avoids passing null to USP. |
| If e.Appointment.RecurrenceParentID <> Nothing Then |
| 'If DirectCast(e.Appointment.RecurrenceParentID, Guid) <> Nothing Then |
| myRecurrenceParentID = e.Appointment.RecurrenceParentID.ToString |
| End If |
| sdsProjectAppointments.ConnectionString = strConnection |
| sdsProjectAppointments.InsertCommand = "usp_insert_project_appointment" |
| sdsProjectAppointments.InsertCommandType = SqlDataSourceCommandType.StoredProcedure |
| 'Set the SQLDataSource Parameters. The first set of parameters are grabbed from |
| 'the new ExceptionAppointment part of the RecurrenceExceptionCreatedEventArgs. |
| 'This contains the new records indivdual start and end times etc... |
| sdsProjectAppointments.InsertParameters.Add("Subject", e.Appointment.Subject.ToString) |
| sdsProjectAppointments.InsertParameters.Add("start", e.Appointment.Start.ToString) |
| sdsProjectAppointments.InsertParameters("start").DbType = DbType.DateTime |
| sdsProjectAppointments.InsertParameters.Add("end", e.Appointment.End.ToString) |
| sdsProjectAppointments.InsertParameters("end").DbType = DbType.DateTime |
| sdsProjectAppointments.InsertParameters.Add("recurrencerule", e.Appointment.RecurrenceRule.ToString) |
| sdsProjectAppointments.InsertParameters.Add("recurrenceparentid", myRecurrenceParentID) |
| 'Now stuff in the parameters we got from our select statement |
| sdsProjectAppointments.InsertParameters.Add("project_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("parent_project_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("release_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("app_env_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("env_comp_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("computer_guid", "00000000-0000-0000-0000-000000000000") |
| sdsProjectAppointments.InsertParameters.Add("status", "1") 'Scheduled |
| sdsProjectAppointments.InsertParameters.Add("appointment_type", "7") 'Type 7 is an informational appointment for the build and release teams |
| sdsProjectAppointments.InsertParameters.Add("colour", "White") 'Unallocated |
| 'Call the update method of the SQLDataSource |
| Try |
| sdsProjectAppointments.Insert() |
| Catch ex As Exception |
| MsgBox("An unhandled exception has occurred. " & ex.Message) |
| End Try |
| End Sub |
After the insert code runs the databound code is called again and any reference to e.appointment.dataitem or even e.appointment.id returns the 'object variable or with block variable not set' error.
Thanks for looking
Jase