Editing resources depending on appointment

4 posts, 0 answers
  1. Kris
    Kris avatar
    13 posts
    Member since:
    Jan 2011

    Posted 28 Oct 2011 Link to this post

    Hello,

    I have added a resource to my scheduler which shows as a dropdown. I need the dropdown to display different values depending on which appointment is selected. What is the best way to go about doing this? Is there an event that I can use to populate the resource just before the edit form displays?
  2. Kris
    Kris avatar
    13 posts
    Member since:
    Jan 2011

    Posted 28 Oct 2011 Link to this post

    After doing more research, I attempted to insert a resource using the AppointmentDataBound event. However, the resource did not show when the form rendered. The code snippit is below. Why doesn't this work? Is there any easier way to create resource that need to have different dropdown values per appointment?

    protected void radSched_AppointmentDataBound(object sender, SchedulerEventArgs e)
            {
                e.Appointment.Resources.Add(new Resource("Calendar", 1, "Community"));
                e.Appointment.Resources.Add(new Resource("Calendar", 2, "Social"));
            }

    Obviously, in my application the calendar name and ID will be dynamic...but I can't even get this to work.
  3. Kris
    Kris avatar
    13 posts
    Member since:
    Jan 2011

    Posted 31 Oct 2011 Link to this post

    Bump.
  4. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 02 Nov 2011 Link to this post

    Hi Kris,

    To achieve the scenario in question, you could define a finite number of resources for the RadScheduler, and in the OnFormCreated server-side event, you could hide the ones that you do not want to show for a particular appointment; As in the code block below:
    void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
    {
        if ((e.Container.Mode == SchedulerFormMode.AdvancedEdit) || (e.Container.Mode == SchedulerFormMode.AdvancedInsert))
        {
            if (e.Appointment.ID.ToString() == "1")
            {
                RadComboBox resourceRoomCombo = e.Container.FindControl("ResRoom") as RadComboBox;
                resourceRoomCombo.Visible = false;
                WebControl resWebcontrol1 = (WebControl)e.Container.FindControl("LblResRoom");
                resWebcontrol1.Parent.Visible = false;
                resWebcontrol1.Controls.Clear();
            }
        }
    }
    <telerik:RadScheduler runat="server" ID="RadScheduler1"
        OnFormCreated="RadScheduler1_FormCreated">
        <AdvancedForm Modal="true"/>
        <ResourceTypes>
            <telerik:ResourceType DataSourceID="RoomsDataSource" ForeignKeyField="RoomID"
                KeyField="ID" Name="Room" TextField="RoomName" />
            <telerik:ResourceType DataSourceID="UsersDataSource" ForeignKeyField="UserID"
                KeyField="ID" Name="User" TextField="UserName" />
        </ResourceTypes>
    </telerik:RadScheduler>
    <asp:SqlDataSource ID="UsersDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM [Users]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="RoomsDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM [Rooms]"></asp:SqlDataSource>
    The example is using the Telerik.mdf database, defined with the following connection string: TelerikConnectionString.

    Also, another approach could be to define an advanced edit template for the RadScheduler, and define asp.net controls/elements in there. This way you will not have to deal with resources. In the following code library you could find a demo project, which demonstrates how to implement related RadComboBoxes inside of the advanced form of the RadScheduler: Related Load on Demand RadComboBoxes in the advanced form of the RadScheduler. You could modify the demo project, in order to best fit your needs.

    I hope this is helpful.

    Greetings,
    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
Back to Top