Bind Gantt To Data
- 2 minutes to read
The Gantt control can operate only in bound mode. It supports standard data source types including SqlDataSource, ObjectDataSource, XmlDataSource, AccessDataSource, and SiteMapDataSource.
#Data Source
The Gantt control requires a separate data source for each of the following objects:
- Tasks (TasksDataSourceID)
- Dependencies (DependenciesDataSourceID)
- Resources (ResourcesDataSourceID)
- Resource Assignments (ResourceAssignmentsDataSourceID)
Note
Refer to the following topics to learn how to generate sample data for the Gantt (SQL script and C# code):
<dx:ASPxGantt ID="Gantt" runat="server" Width="100%" ClientInstanceName="clientGantt"
KeyFieldName="ID" ParentFieldName="ParentID"
TasksDataSourceID="TasksDataSource"
DependenciesDataSourceID="DependenciesDataSource"
ResourcesDataSourceID="ResourcesDataSource"
ResourceAssignmentsDataSourceID="ResourceAssignmentsDataSource">
...
</dx:ASPxGantt>
<asp:SqlDataSource ID="TasksDataSource" runat="server"
ConnectionString='<%$ ConnectionStrings:DevelopmentGanttConnectionString %>'
SelectCommand="SELECT * FROM [Tasks]" />
<asp:SqlDataSource ID="DependenciesDataSource" runat="server"
ConnectionString='<%$ ConnectionStrings:DevelopmentGanttConnectionString %>'
SelectCommand="SELECT * FROM [TaskDependecies]" />
<asp:SqlDataSource ID="ResourcesDataSource" runat="server"
ConnectionString='<%$ ConnectionStrings:DevelopmentGanttConnectionString %>'
SelectCommand="SELECT * FROM [Teams]" />
<asp:SqlDataSource ID="ResourceAssignmentsDataSource" runat="server"
ConnectionString='<%$ ConnectionStrings:DevelopmentGanttConnectionString %>'
SelectCommand="SELECT * FROM [TaskTeamRelations]" />
#Mappings
Mappings specify which field in a data source corresponds to an object’s property (task, dependency, resource).
The Gantt control requires mappings for the following objects:
Task (Task)
Mandatory fields for a task object:
Field description
Mapping
A task’s ID.
A task’s parent ID.
A task’s title.
A task’s start date.
A task’s end date.
A task’s color.
Dependency (Dependency)
Mandatory fields for a dependency object:
Field description
Mapping
A predecessor task’s ID.
A successor task’s ID.
A dependency type.
A dependency ID.
Resource (Resource)
Mandatory fields for a resource object:
Field description
Mapping
A task’s resource ID.
A task’s resource name.
A task resource’s color.
Resource Assignment (ResourceAssignment)
Mandatory fields for a resource assignment object:
Field description
Mapping
A task’s resource assignment ID.
A task’s resource ID.
A task’s ID.
<dx:ASPxGantt ID="Gantt" runat="server" Width="100%" ClientInstanceName="clientGantt"
KeyFieldName="ID" ParentFieldName="ParentID"
TasksDataSourceID="TasksDataSource"
DependenciesDataSourceID="DependenciesDataSource"
ResourcesDataSourceID="ResourcesDataSource"
ResourceAssignmentsDataSourceID="ResourceAssignmentsDataSource">
<Columns>
...
</Columns>
<Mappings>
<Task Key="ID" ParentKey="ParentID" Title="Subject" Start="StartDate" End="EndDate" Progress="PercentComplete" Color="Color" />
<Dependency Key="ID" PredecessorKey="ParentID" SuccessorKey="DependentID" DependencyType="Type" />
<Resource Key="ID" Name="Name" Color="Color" />
<ResourceAssignment Key="ID" TaskKey="TaskID" ResourceKey="TeamID" />
</Mappings>
</dx:ASPxGantt>
#Limitation
- The ASPxGantt control displays the progress of the task in integer format even if it is in decimal format in the data source.