How to Populate Gantt

4 posts, 1 answers
  1. Richard
    Richard avatar
    9 posts
    Member since:
    Nov 2010

    Posted 29 Nov 2014 Link to this post


    I'm trying to load the information as a Gantt Chart. Because my data is not structure as the gantt task require, i'created a view with the suggested structure for the Tasks, (i don't know how to populate the dependencies). So my gantt view's structure looks like:
    [ID] [int]
    [ParentID] [int]
    [OrderID] [int]
    [Title] [ntext]
    [Start] [datetime]
    [End] [datetime]
    [PercentComplete] [decimal]
    [Summary] [bit]

    Now, in my ganttPage.aspx 
    <telerik:RadGantt runat="server" ID="GanttChart" Skin="Silk" ListWidth="400px" Height="350px" Width="1000px" SelectedView="WeekView" AutoGenerateColumns="false" WorkWeekStart="Monday" WorkWeekEnd="Friday">
            <telerik:GanttBoundColumn DataField="Title" HeaderText="Attivita" DataType="String" UniqueName="Title" Width="150px" AllowEdit="false"></telerik:GanttBoundColumn>
            <telerik:GanttBoundColumn DataField="Start" HeaderText="Inizio" DataType="DateTime" UniqueName="Start" DataFormatString="dd/MM/yy" Width="65px" AllowEdit="false" />
            <telerik:GanttBoundColumn DataField="End" HeaderText="Fine" DataType="DateTime" UniqueName="End" DataFormatString="dd/MM/yy" Width="65px" AllowEdit="false" />
            <telerik:GanttBoundColumn DataField="PercentComplete" HeaderText="Completamento" DataType="Number" UniqueName="PercentComplete" Width="110px" AllowEdit="false" />
        <DayView UserSelectable="true" SlotWidth="65px" DayHeaderDateFormat="ddd" TimeHeaderDateFormat="H:mm" />
        <WeekView UserSelectable="true" DayHeaderDateFormat="ddd" SlotWidth="65px" WeekHeaderDateFormat="ddd" />
        <YearView UserSelectable="true" MonthHeaderDateFormat="M" YearHeaderDateFormat="Y" SlotWidth="65px" />
        <MonthView UserSelectable="true" SlotWidth="65px" MonthHeaderDateFormat="M" WeekHeaderDateFormat="ddd M/dd" />

    So i don't wanna use the declarative binding because i need more flexibility, The Xml provider will not solve my problem. And the data source... i can't make it work :S...  Would be great!

    I also want to show multiple projects in my gantt chart, it's that possible?

    help me please...

  2. Answer
    Bozhidar avatar
    1101 posts

    Posted 01 Dec 2014 Link to this post


    DataBinding through the DataSource property in Code Behind was introduced in the official release of the control, in Q3 2014, so if you are using the older version you won't be able to use it. And if you want to create a more specific binding scenario, you can create a custom provider, as explained in the following help article:

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard
    Richard avatar
    9 posts
    Member since:
    Nov 2010

    Posted 01 Dec 2014 in reply to Bozhidar Link to this post

    Hi, thanks for the answer!

    i've been trying many things to make it work. i have found some problems. 
    The first one:
    I  Can't use a list of ITask with .Net Framework 3.5, for some reason the code 

     public override List<ITask> GetTasks()
                var tasks = new List<ITask>();

                using (var db = new GanttEntities())
                    tasks.AddRange(db.GanttTasks.ToList().Select(task => new Task
                        ID = task.ID,
                        ParentID = task.ParentID,
                        OrderID = task.OrderID,
                        Start = task.Start,
                        End = task.End,
                        PercentComplete = task.PercentComplete,
                        Summary = task.Summary,
                        Title = task.Title,
                        Expanded = task.Expanded.HasValue && task.Expanded.Value

                return tasks;

     the way it works for me is

    public class myTask
            public int Id { get; set; }
            public int ParentId { get; set; }
            public int OrderId { get; set; }
            public DateTime Start { get; set; }
            public DateTime End { get; set; }
            public decimal PercentComplete { get; set; }
            public bool Summary { get; set; }
            public string Title { get; set; }
            public bool Expanded { get; set; }
     public override List<ITask> GetTasks()

                List<ITask> tasks = new List<ITask>();

                using (var db = new GanttEntities())
                   var query = (from t in db.GanttTasks select new myTask
                                     Id = f.Id,
                                     ParentId = t.ParentId == null ? 0 : (int)t.ParentId,
                                     OrderId = t.ProjectId,
                                     Start = (DateTime)t.Start,
                                     End = (DateTime)t.End,
                                     PercentComplete = t.PercentComplete == null ? 0 : (decimal)t.PercentComplete,
                                     Summary = t.Summary == 1 ? true : false,
                                     Title = t.Title,
                                     Expanded = true

    Then iterate and add it to the list of task as a Task item.  Another problem is the casting of an Int to an Object from the IDs (ID, ProjectID, OrderID).

    The Second problems is that the GanttChart, is not showing anything.  in my page's code behind i'm using:

    GanttChart.Provider = new GanttProvider();

    as the suggested example. 

    There's anything wrong in my code?

    Thanks again!!!
  5. Bozhidar
    Bozhidar avatar
    1101 posts

    Posted 03 Dec 2014 Link to this post


    I've attached a runnable sample page demonstrating databinding through the DataSource property of the Gantt control in code behind. Please run it on your end and see if any issues arise.

Back to Top