New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Use CustomFields in Gantt with a simple CustomProvider

HOW TO 

This article shows a simplified version of the Custom Tasks Field with a simple CustomProvider using Session instead of EntityFramework.

DESCRIPTION

The Custom Tasks field require you to have a custom Task class and in order to use a custom Task class, you should create a CustomProvider. This example is using the Custom Provider from the RadGantt with Simple CustomProvider using collections in Session KB article.

SOLUTION

CustomTask.cs

using System.Collections.Generic;
using Telerik.Web.UI.Gantt;

public class CustomTask : Task
{
    public CustomTask()
        : base()
    {
    }

    public string Description
    {
        get { return (string) (ViewState["Description"] ?? ""); }
        set { ViewState["Description"] = value; }
    }

    public string MyCustomField
    {
        get { return (string) (ViewState["MyCustomField"] ?? ""); }
        set { ViewState["MyCustomField"] = value; }
    }

    protected override IDictionary<string, object> GetSerializationData()
    {
        var dict = base.GetSerializationData();
        dict["Description"] = Description;
        dict["MyCustomField"] = MyCustomField;
        return dict;
    }

    public override void LoadFromDictionary(System.Collections.IDictionary values)
    {
        base.LoadFromDictionary(values);

        Description = (string) values["Description"];
        MyCustomField = (string) values["MyCustomField"];
    }
}
<telerik:RadGantt runat="server" ID="RadGantt1" SelectedView="WeekView" AutoGenerateColumns="false">
    <Columns>
        <telerik:GanttBoundColumn DataField="ID" Width="90px"></telerik:GanttBoundColumn>
        <telerik:GanttBoundColumn DataField="Title"></telerik:GanttBoundColumn>
        <telerik:GanttBoundColumn DataField="Description" HeaderText="Description"
            DataType="String" UniqueName="Description"></telerik:GanttBoundColumn>
         <telerik:GanttBoundColumn DataField="MyCustomField" HeaderText="MyCustomField"
            DataType="String" UniqueName="MyCustomField"></telerik:GanttBoundColumn>
    </Columns>
    <CustomTaskFields>
        <telerik:GanttCustomField PropertyName="Description" ClientPropertyName="description" />
        <telerik:GanttCustomField PropertyName="MyCustomField" ClientPropertyName="myCustomField" />
    </CustomTaskFields>
</telerik:RadGantt>

See also

Downloads

You can find atached the projects demonstrating the described approached here:

In this article
Not finding the help you need? Improve this article