BUT if a student is selected and no type is then type to be selected too. here is my code: THE PROBLEM IS THAT THE SECOND IF STATEMENT DOES NOT ADD THE RESOURSE "types".
protected void RadScheduler1_AppointmentInsert(object sender, Telerik.Web.UI.SchedulerCancelEventArgs e)
{
if (e.Appointment.Resources.Count < 1)
{
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("types", 2));
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("students", 1));
}
if ((e.Appointment.Resources.GetResourceByType("students") != null) && (e.Appointment.Resources.GetResourceByType("types") == null))
{
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("types", 2));
}
}
Please give me a solution
thanks
5 Answers, 1 is accepted
Everything looks fine with your code. Can you confirm that the code in the second if statement is indeed executed and that RadScheduler1.Resources.GetResource("types", 2) returns a valid resource?
Kind regards,
Tsvetomir Tsonev
the Telerik team

The code in the second if statement is indeed executed andRadScheduler1.Resources.GetResource("types", 2) returns a valid resource (key 2 text "professional") ............................BUT the Resource "type" is not added to the SQL table that holds dbo.schedule!!!!
The first if statement is executed and it adds the 2 resources!!! when the statment is fullfilled.
Thanks for your help!!
Well, that's very strange behavior. Can we take a look at the page source code, including the RadScheduler and the data source definition?
You can also use a tool like SQL Profiler to examine the actual query that is being executed. Check if all parameters are being set correctly.
Kind regards,
Tsvetomir Tsonev
the Telerik team

http://medical.arcww.gr/Default.aspx
If you add an appointment with no resourses then you may open to see that the first contition worked and 2 resources added.(rooms and types)
If you add an appointment with only room resource after you open the appointment you will see that the second contition although fulfilled it did not add the resource "type". (I can asure you that the RadScheduler1.Resources.GetResource("rooms", 2) has a value and I see it in debuging)
I believe it's a bug in the telerik scheduler control.
Below I send you the .aspx and cs Code that are very straightforward!!!
ASPX
----------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="scheduler.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager Runat="server">
</telerik:RadScriptManager>
<telerik:RadScheduler ID="RadScheduler1" runat="server"
DataEndField="sc_end_time" DataKeyField="sc_id"
DataRecurrenceField="sc_RecurrenceRule"
DataRecurrenceParentKeyField="sc_RecurrenceParentID" DataSourceID="SqlDSchedule"
DataStartField="sc_start_time" DataSubjectField="sc_subject"
HoursPanelTimeFormat="htt" Skin="Office2007"
ValidationGroup="RadScheduler1" DayEndTime="22:00:00"
Width="70%" WorkDayEndTime="22:00:00"
onappointmentinsert="RadScheduler1_AppointmentInsert">
<WeekView DayEndTime="22:00:00" WorkDayEndTime="22:00:00" />
<Localization AdvancedAllDayEvent="All day"></Localization>
<AdvancedForm Modal="true" />
<TimelineView GroupBy="Calendar" GroupingDirection="Vertical" />
<AdvancedForm DateFormat="d/M/yyyy" TimeFormat="h:mm tt"></AdvancedForm>
<ResourceTypes>
<telerik:ResourceType KeyField="room_id" Name="rooms" TextField="room_name" ForeignKeyField="sc_room"
DataSourceID="RoomsDataSource" />
<telerik:ResourceType KeyField="type_id" Name="types" TextField="type_name" ForeignKeyField="sc_type"
DataSourceID="TypesDataSource" />
</ResourceTypes>
<DayView DayEndTime="22:00:00" WorkDayEndTime="22:00:00" />
<MultiDayView DayEndTime="22:00:00" WorkDayEndTime="22:00:00" />
</telerik:RadScheduler>
<asp:SqlDataSource ID="SqlDSchedule" runat="server"
ConnectionString="<%$ ConnectionStrings:MedisConnectionString %>"
DeleteCommand="DELETE FROM [Schedule] WHERE [sc_id] = @sc_id"
InsertCommand="INSERT INTO [Schedule] ([sc_start_time], [sc_end_time], [sc_subject], [sc_RecurrenceRule], [sc_RecurrenceParentID], [sc_memo], [sc_room], [sc_type]) VALUES (@sc_start_time, @sc_end_time, @sc_subject, @sc_RecurrenceRule, @sc_RecurrenceParentID, @sc_memo, @sc_room, @sc_type)"
SelectCommand="SELECT * FROM [Schedule]"
UpdateCommand="UPDATE [Schedule] SET [sc_start_time] = @sc_start_time, [sc_end_time] = @sc_end_time, [sc_subject] = @sc_subject, [sc_RecurrenceRule] = @sc_RecurrenceRule, [sc_RecurrenceParentID] = @sc_RecurrenceParentID, [sc_memo] = @sc_memo, [sc_room] = @sc_room, [sc_type] = @sc_type WHERE [sc_id] = @sc_id">
<DeleteParameters>
<asp:Parameter Name="sc_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="sc_start_time" Type="DateTime" />
<asp:Parameter Name="sc_end_time" Type="DateTime" />
<asp:Parameter Name="sc_subject" Type="String" />
<asp:Parameter Name="sc_RecurrenceRule" Type="String" />
<asp:Parameter Name="sc_RecurrenceParentID" Type="Int32" />
<asp:Parameter Name="sc_memo" Type="String" />
<asp:Parameter Name="sc_room" Type="Int32" />
<asp:Parameter Name="sc_type" Type="Int32" />
<asp:Parameter Name="sc_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="sc_start_time" Type="DateTime" />
<asp:Parameter Name="sc_end_time" Type="DateTime" />
<asp:Parameter Name="sc_subject" Type="String" />
<asp:Parameter Name="sc_RecurrenceRule" Type="String" />
<asp:Parameter Name="sc_RecurrenceParentID" Type="Int32" />
<asp:Parameter Name="sc_memo" Type="String" />
<asp:Parameter Name="sc_room" Type="Int32" />
<asp:Parameter Name="sc_type" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="RoomsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MedisConnectionString %>"
SelectCommand="SELECT * FROM [Rooms]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="TypesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MedisConnectionString %>"
SelectCommand="SELECT * FROM [Types]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
.CS
----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadScheduler1_AppointmentInsert(object sender, Telerik.Web.UI.SchedulerCancelEventArgs e)
{
if (e.Appointment.Resources.Count < 1)
{
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("rooms", 2));
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("types", 1));
}
if ((e.Appointment.Resources.GetResourceByType("types") != null) && (e.Appointment.Resources.GetResourceByType("rooms") == null))
{
e.Appointment.Resources.Add(RadScheduler1.Resources.GetResource("rooms", 2));
}
}
}
Thanks for your help
Seris
Thank you for setting-up a live URL and sending us the sample code.
You say that:
If you add an appointment with only room resource after you open the appointment you will see that the second contition although fulfilled it did not add the resource "type"
But the code checks for exactly the opposite - if you don't have a room, but have a specified type it will add a room.
I've tested both scenarios just to be sure and I confirm that the second resource is not being added on the live URL.
I then tested the application locally and it works - if I add only type the code adds room as well. See the attached project. I've used your code as is and created a database schema to match.
My only guess is that something is happening at the database level, but I can't say what at this point.
Greetings,
Tsvetomir Tsonev
the Telerik team