This is a migrated thread and some comments may be shown as answers.

Databind Resources Prgrammaticlly

4 Answers 118 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Timothy Kruszewski
Top achievements
Rank 1
Timothy Kruszewski asked on 02 Sep 2010, 04:02 PM
I have a scheduler that bind resouces using an entity data source and it works just fine.  However, I would like to bind the resouces via C# and can't figure out how find the control or what in what method this needs to be done.  An example would be greatly appreciated.

Thanks

<ResourceTypes>
<telerik:ResourceType DataSourceID="edsCategories" ForeignKeyField="CategoryID" KeyField="CategoryID"
                    Name="Category" TextField="Category" /> 
<
/ResourceTypes
  
  
<asp:EntityDataSource ID="edsCategories" runat="server" ConnectionString="name=ProNetData"
        DefaultContainerName="ProNetData" EntitySetName="AppointmentCategories">
    </asp:EntityDataSource>

4 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 03 Sep 2010, 03:25 PM
Hello Timothy Kruszewski,

You'll need to subscribe to the OnInit or Page_Load events of the RadScheduler. Here's a sample code:

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ResourceType Foreman = new ResourceType("Foreman");
        Foreman.ForeignKeyField = "UserID";
        RadScheduler1.ResourceTypes.Add(Foreman);
        RadScheduler1.Resources.Add(new Resource("Foreman", 1, "A"));
        RadScheduler1.Resources.Add(new Resource("Foreman", 2, "B"));
        RadScheduler1.Resources.Add(new Resource("Foreman", 3, "C"));
        RadScheduler1.GroupBy = "Foreman";
        RadScheduler1.GroupingDirection = GroupingDirection.Vertical;
    }

Hope this helps.

Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 03 Sep 2010, 05:30 PM
The problem I'm having now is that my OnDataBound event is not able to find the resource.  Is there a way I can have the resource type listed on the aspx page like this and then just add the datasource to it via the C# code?

<

 

 

ResourceTypes>

 

 

 

<telerik:ResourceType ForeignKeyField="UserID" KeyField="UserID"

 

 

 

Name="User Name" TextField="UserName" />

 

 

 

</ResourceTypes>

 



protected override void OnInit(EventArgs e) 
   {
       base.OnInit(e);
       using (ProNetData d = new ProNetData())
       {
           var users = (from c in d.AppointmentUsers
                        where c.SyncUsers == true
                        orderby c.FirstName
                        select c).ToList();
           ResourceType UserName = new ResourceType("User Name");
           UserName.ForeignKeyField = "UserID";
           UserName.KeyField = "UserID";
           UserName.TextField = "UserName";
           UserName.DataSource = users;
            
       }
   }

protected void RadScheduler1_OnDataBound(object sender, EventArgs e)
    {
        foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User Name"))
        {
            RadScheduler1.Resources.Remove(res);
        }
  
        List<Resource> list = new List<Resource>();
        foreach (Telerik.Web.UI.Appointment a in RadScheduler1.Appointments.GetAppointmentsInRange(RadScheduler1.VisibleRangeStart, RadScheduler1.VisibleRangeEnd))
        {
            Resource userName = a.Resources.GetResourceByType("User Name");
            if (userName != null && !list.Contains(userName))
            {
                list.Add(userName);
            }
  
            foreach (ListItem l in cblUsers.Items)
            {
                if (l.Selected)
                {
                    Resource name = new Resource("User Name", int.Parse(l.Value), l.Text);
                    if (!list.Contains(name))
                    {
                        list.Add(name);
                    }
                }
            }
        }
  
        list.Sort(delegate(Resource resA, Resource resB)
        {
            return resA.Text.CompareTo(resB.Text);
        });
        RadScheduler1.Resources.AddRange(list);
        RadScheduler1.ResourceTypes.FindByName("User Name").AllowMultipleValues = true;
    }

0
Accepted
Veronica
Telerik team
answered on 09 Sep 2010, 03:07 PM
Hi Timothy Kruszewski,

In your code I don't see where do you add the newly created ResourceType to the RadScheduler.
Please take a look at the line highlighted in yellow:

protected override void OnInit(EventArgs e)
   {
       base.OnInit(e);
       using (ProNetData d = new ProNetData())
       {
           var users = (from c in d.AppointmentUsers
                        where c.SyncUsers == true
                        orderby c.FirstName
                        select c).ToList();
           ResourceType UserName = new ResourceType("User Name");
           UserName.ForeignKeyField = "UserID";
           UserName.KeyField = "UserID";
           UserName.TextField = "UserName";
           UserName.DataSource = users;
           RadScheduler1.ResourceTypes.Add(UserName);
       }
   }

Kind regards,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 09 Sep 2010, 07:24 PM
That solved the problem.  Thanks
Tags
Scheduler
Asked by
Timothy Kruszewski
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Timothy Kruszewski
Top achievements
Rank 1
Share this question
or