I have make a scheduler based on your exemple. It Wok well, his is my method to inizialize object and dataBound
http://localhost:8301/radcontrols_aspnetajax/scheduler/examples/bindtolist/defaultcs.aspx
now, if I change the InitializeResources() method in this way
it work on page load (the combo box User is populated correctly) but in past back during the method RadScheduler1_AppointmentDataBound in this row
Resource userRes = e.Appointment.Resources.GetResourceByType("User");
the userRes object is always null, why?
http://localhost:8301/radcontrols_aspnetajax/scheduler/examples/bindtolist/defaultcs.aspx
private void InitializeResources() { ResourceType resType = new ResourceType("User", false); resType.ForeignKeyField = "UserID"; resType.Name = "User"; RadScheduler1.ResourceTypes.Add(resType); //add uer DataView listUser = (DataView)ObjectDataSourceFilterContatti.Select(); foreach (DataRow user in listUser.Table.Rows) { int key = Convert.ToInt32(user["idAnagrafica"]); string value = user["Nome"].ToString(); Resource r = new Resource("User", key, value); RadScheduler1.Resources.Add(r); } }protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e) { //recupero l'utente collegato all'appuntamento Resource userRes = e.Appointment.Resources.GetResourceByType("User"); if (userRes != null) { string key = userRes.Key.ToString(); //DO SOMETHING............... } }ResourceType resType = new ResourceType("User", false); resType.DataSourceID = "ObjectDataSourceFilterContatti"; resType.ForeignKeyField = "UserID"; resType.KeyField = "idAnagrafica"; resType.TextField = "Nome"; resType.Name = "User"; RadScheduler1.ResourceTypes.Add(resType);it work on page load (the combo box User is populated correctly) but in past back during the method RadScheduler1_AppointmentDataBound in this row
Resource userRes = e.Appointment.Resources.GetResourceByType("User");
the userRes object is always null, why?
3 Answers, 1 is accepted
0
Hi Francesco,
I tried to reproduce the issue but to no avail.
I am interested where did you call the InitializeResources() method? Did you call it in the OnInit event? Could you please send me your full code so I can inspect it and help you?
Greetings,
veronica Milcheva
the Telerik team
I tried to reproduce the issue but to no avail.
I am interested where did you call the InitializeResources() method? Did you call it in the OnInit event? Could you please send me your full code so I can inspect it and help you?
Greetings,
veronica Milcheva
the Telerik team
0
Francesco
Top achievements
Rank 1
answered on 21 Mar 2011, 05:27 PM
yes I paste my full code, verry thanks...
<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Trilance.SalesNet.Web.Pages.WebForm4" EnableTheming="True" %> <asp:content id="Content1" contentplaceholderid="head" runat="server"> </asp:content> <asp:content id="Content5" contentplaceholderid="TrilanceMasterContent" runat="server"> <!------------------------------------------------------------------- -------------------------- CONFIGURAZIONE RAD AJAX PANEL ------------ -------------------------------- INIZIO -----------------------------> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" RequestQueueSize="10"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxPanel1"> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel> <!----------------------------------- FINE -----------------------------> <!-- [ MAIN ] --> <div id="boxMainWrap"> <!-- [ CONTENT ] --> <div id="boxMainContent" class=""> <!-- [ CONTENT > BODY ] --> <div id="boxMainContentBody" class="page_controls dataentry"> <!-- CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT CONTENT --> <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" width="100%" height="100%" LoadingPanelID="RadAjaxLoadingPanel1"> <table id="table1" cellpadding="10" cellspacing="0" width="100%"> <tr> <td width="200px" height="100px" valign="top"> <telerik:RadCalendar ID="RadCalendar1" Runat="server" EnableMultiSelect="False" onselectionchanged="RadCalendar1_SelectionChanged" AutoPostBack="True"> </telerik:RadCalendar> </td> <td rowspan="2" valign="top" width="100%"> <div> <telerik:RadScheduler runat="server" ID="RadScheduler1" DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End" DayStartTime="07:00:00" DayEndTime="20:00:00" TimeZoneOffset="03:00:00" OnAppointmentInsert="RadScheduler1_AppointmentInsert" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" OnAppointmentDelete="RadScheduler1_AppointmentDelete" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentId" Height="100%" onappointmentdatabound="RadScheduler1_AppointmentDataBound" ondatabound="RadScheduler1_DataBound" Culture="Italian (Italy)" EditFormTimeFormat="HH.mm" FirstDayOfWeek="Monday" HoursPanelTimeFormat="HH" SelectedView="WeekView" StartInsertingInAdvancedForm="True" onformcreating="RadScheduler1_FormCreating"> <DayView DayEndTime="20:00:00" DayStartTime="07:00:00" WorkDayEndTime="20:00:00" WorkDayStartTime="07:00:00" /> <AdvancedForm Modal="true" TimeFormat="HH.mm" /> <TimelineView UserSelectable="false" /> <WeekView DayEndTime="20:00:00" DayStartTime="07:00:00" WorkDayEndTime="07:00:00" WorkDayStartTime="20:00:00" /> <TimeSlotContextMenuSettings EnableDefault="true" /> <AppointmentContextMenuSettings EnableDefault="true" /> <%-- <ResourceTypes> <telerik:ResourceType KeyField="idAnagrafica" Name="Agente" TextField="Nome" ForeignKeyField="idAnagrafica" DataSourceID="ObjectDataSourceFilterContatti" /> </ResourceTypes>--%> </telerik:RadScheduler> </div> </td> </tr> <tr> <td height="100%" valign="top"> <telerik:RadListBox ID="RadListBox1" runat="server" DataSourceID="ObjectDataSourceFilterContatti" DataTextField="Nome" DataValueField="idAnagrafica" Width="100%" AutoPostBack="True" CheckBoxes="True" EnableDragAndDrop="True" onitemcheck="RadListBox1_ItemCheck"> </telerik:RadListBox> </td> </tr> </table> </telerik:RadAjaxPanel> </div> </div> </div> <asp:ObjectDataSource ID="ObjectDataSourceFatture" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="SearchPagedFatturaEntity" TypeName="Trilance.WEB.Helper.FatturaEntityHelper" CacheExpirationPolicy="Sliding" CacheKeyDependency="Fatture" EnableCaching="True" EnableViewState="False"> <SelectParameters> <asp:Parameter DefaultValue="idAnagrafica = '100001'" Name="strSearchCriteria" Type="String" /> <asp:Parameter Name="strOrderBy" Type="String" /> <asp:Parameter DefaultValue="1" Name="intStartIndex" Type="Int32" /> <asp:Parameter DefaultValue="15" Name="intPageSize" Type="Int32" /> <asp:Parameter Direction="Output" Name="intTotal" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> <asp:ObjectDataSource ID="ObjectDataSourceFilterContatti" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="SearchPagedContattoEntity" TypeName="Trilance.WEB.Helper.ContattoEntityHelper"> <SelectParameters> <asp:Parameter DefaultValue="Nome like '%mar%'" Name="strSearchCriteria" Type="String" /> <asp:Parameter DefaultValue="Nome" Name="strOrderBy" Type="String" /> <asp:Parameter DefaultValue="1" Name="intStartIndex" Type="Int32" /> <asp:Parameter DefaultValue="15" Name="intPageSize" Type="Int32" /> <asp:Parameter Direction="InputOutput" Name="intTotal" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> </asp:content> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.Web.UI; using Trilance.SalesNet.Web.Class.Base; using System.Data; namespace Trilance.SalesNet.Web.Pages { public partial class WebForm4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Request.Form["Calendar1"]; //Control placeHolder = PreviousPage.Form.FindControl("TrilanceMasterContent"); //RadPanelBar RadPanelBarLeft = (RadPanelBar)placeHolder.FindControl("RadPanelBarLeft"); //RadCalendar Calendar1 = (RadCalendar)RadPanelBarLeft.FindItemByValue("pnlCalendar").FindControl("Calendar1"); //RadScheduler1.SelectedDate = Calendar1.SelectedDate; } private const string AppointmentsKey = "Telerik.Web.Examples.Scheduler.BindToList.CS.Apts"; private List<TrilanceScheduleBase> Appointments { get { List<TrilanceScheduleBase> sessApts = Session[AppointmentsKey] as List<TrilanceScheduleBase>; if (sessApts == null) { sessApts = new List<TrilanceScheduleBase>(); Session[AppointmentsKey] = sessApts; } return sessApts; } } protected override void OnInit(EventArgs e) { base.OnInit(e); if (!IsPostBack) { Session.Remove(AppointmentsKey); InitializeResources(); InitializeAppointments(); //set dafult date //if (RadCalendar1.SelectedDate == null) //{ RadCalendar1.SelectedDate = DateTime.Now; //} } //InitializeResources(); RadScheduler1.DataSource = Appointments; } protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e) { Appointments.Add(new TrilanceScheduleBase(e.Appointment)); //metto il check! Resource UserRes = e.Appointment.Resources.GetResourceByType("Agente"); string key = UserRes.Key.ToString(); //lo cerco nella listbox e verifico se è checcato o meno! RadListBoxItem item = RadListBox1.FindItemByValue(key); item.Checked = true; } protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e) { TrilanceScheduleBase ai = FindById(e.ModifiedAppointment.ID); ai.CopyInfo(e.ModifiedAppointment); } protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e) { Appointments.Remove(FindById(e.Appointment.ID)); } private void InitializeResources() { ResourceType resType = new ResourceType("Agente", false); //resType.DataSourceID = "ObjectDataSourceFilterContatti"; //resType.DataSource = ObjectDataSourceFilterContatti.Select(); resType.ForeignKeyField = "UserID"; //resType.KeyField = "idAnagrafica"; //resType.TextField = "Nome"; //resType.Name = "User"; RadScheduler1.ResourceTypes.Add(resType); //add uer DataView listUser = (DataView)ObjectDataSourceFilterContatti.Select(); foreach (DataRow User in listUser.Table.Rows) { int key = Convert.ToInt32(User["idAnagrafica"]); string value = User["Nome"].ToString(); Resource r = new Resource("Agente", key, value); RadScheduler1.Resources.Add(r); } /* RadScheduler1.Resources.Add(new Resource("User", 1, "Alex")); RadScheduler1.Resources.Add(new Resource("User", 2, "Bob")); RadScheduler1.Resources.Add(new Resource("User", 3, "Charlie")); */ } private void InitializeAppointments() { /* DateTime start = DateTime.UtcNow.Date; start = start.AddHours(6); Appointments.Add(new TrilanceScheduleBase("Take the car to the service", start, start.AddHours(1), string.Empty, null, 1)); Appointments.Add(new TrilanceScheduleBase("Meeting with Alex", start.AddHours(2), start.AddHours(3), string.Empty, null, 2)); start = start.AddDays(-1); DateTime dayStart = RadScheduler1.UtcDayStart(start); Appointments.Add(new TrilanceScheduleBase("Bob's Birthday", dayStart, dayStart.AddDays(1), string.Empty, null, 1)); Appointments.Add(new TrilanceScheduleBase("Call Charlie about the Project", start.AddHours(2), start.AddHours(3), string.Empty, null, 2)); start = start.AddDays(2); Appointments.Add(new TrilanceScheduleBase("Get the car from the service", start.AddHours(2), start.AddHours(3), string.Empty, null, 1)); */ } private TrilanceScheduleBase FindById(object ID) { foreach (TrilanceScheduleBase ai in Appointments) { if (ai.ID.Equals(ID)) { return ai; } } return null; } protected void RadCalendar1_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e) { if (RadCalendar1.SelectedDates.Count > 0) { RadScheduler1.SelectedDate = RadCalendar1.SelectedDate; } } protected void RadListBox1_SelectedIndexChanged(object sender, EventArgs e) { //RadScheduler1.Rebind(); } protected void RadScheduler1_DataBound(object sender, EventArgs e) { } protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e) { //recupero l'utente collegato all'appuntamento Resource UserRes = e.Appointment.Resources.GetResourceByType("Agente"); //if (UserRes != null) //{ string key = UserRes.Key.ToString(); //lo cerco nella listbox e verifico se è checcato o meno! RadListBoxItem item = RadListBox1.FindItemByValue(key); if (item.Checked) { e.Appointment.Visible = true; } else { e.Appointment.Visible = false; } //} } protected void RadListBox1_ItemCheck(object sender, RadListBoxItemEventArgs e) { RadScheduler1.Rebind(); } protected void RadScheduler1_FormCreating(object sender, SchedulerFormCreatingEventArgs e) { //se selezionato a sx User lo assegno quell'User come default nella combo! string UserKey = RadListBox1.SelectedValue; if (!string.IsNullOrEmpty(UserKey)) { int key = Convert.ToInt32(UserKey); //ricerco la risorsa nella lista dello scadenziario Resource UserRes = RadScheduler1.Resources.GetResource("Agente", key); //la assegno all'appuntamento in questione e.Appointment.Resources.Add(UserRes); } } } } I don't Understand how to use ForeignKeyField property, If I made a new ResourceType "Agente" object it work correctly if and only if the ForeignKeyField = "UserID" if I change this property to "MyID" I have a javascript generic error. I am very confused. I hope you can help me, thank a lot
0
Hi Francesco,
Unfortunately I am not able to see what is the problem without debugging your code.
Could you please open a new support thread and attach the full code in a .zip file so I can inspect it and help you?
Thank you!
Best wishes,
Veronica Milcheva
the Telerik team
Unfortunately I am not able to see what is the problem without debugging your code.
Could you please open a new support thread and attach the full code in a .zip file so I can inspect it and help you?
Thank you!
Best wishes,
Veronica Milcheva
the Telerik team