Gantt - Resources

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

This example demonstrates how to populate RadGantt with enabled Resources from SqlDataSource. You need to have four SqlDataSource controls in order to acquire the data set for the tasks, their dependencies, the resources and the assignments. In addition, you need to configure the properties available under the DataBindings tag, in order to match the fields in the database tables.

  • DefaultVB.aspx
<%@ Page Language="vb" AutoEventWireup="true"  %>

<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />

    <div class="demo-container no-bg">
        <telerik:RadGantt RenderMode="Lightweight" runat="server" ID="RadGantt1" 
            DataSourceID="TasksDataSource" 
            DependenciesDataSourceID="DependenciesDataSource" 
            ResourcesDataSourceID="ResourcesDataSource"
            AssignmentsDataSourceID="AssignmentsDataSource"
            SelectedView="MonthView" 
            Height="600px" 
            ListWidth="450px"
            EnableResources="true"
            AutoGenerateColumns="false">
            <Columns>
                <telerik:GanttBoundColumn DataField="Title" DataType="String"></telerik:GanttBoundColumn>
                <telerik:GanttResourceColumn HeaderText="Asssigned Resources"></telerik:GanttResourceColumn>
            </Columns>

            <DataBindings>
                <TasksDataBindings
                    IdField="ID" ParentIdField="ParentID"
                    StartField="Start" EndField="End"
                    OrderIdField="OrderID"
                    SummaryField="Summary"
                    TitleField="Title" PercentCompleteField="PercentComplete" />
                <DependenciesDataBindings
                    TypeField="Type" IdField="ID"
                    PredecessorIdField="PredecessorID"
                    SuccessorIdField="SuccessorID" />
                <ResourcesDataBindings IdField="ID" 
                    TextField="Name" 
                    ColorField="Color" />
                <AssignmentsDataBindings IdField="ID" 
                    TaskIdField="TaskID" 
                    ResourceIdField="ResourceID" 
                    UnitsField="Units" />
            </DataBindings>
        </telerik:RadGantt>
    </div>

    <sds:SessionDataSource ID="TasksDataSource" runat="server" DisplayWarning="false"
        PrimaryKeyFields="ID" ProviderName="System.Data.SqlClient" 
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        DeleteCommand="DELETE FROM [GanttTasks] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [GanttTasks] ([ParentID], [OrderID], [Title], [Start], [End], [PercentComplete], [Expanded], [Summary]) VALUES (@ParentID, @OrderID, @Title, @Start, @End, @PercentComplete, @Expanded, @Summary)"
        SelectCommand="SELECT * FROM [GanttTasks]"
        UpdateCommand="UPDATE [GanttTasks] SET [ParentID] = @ParentID, [OrderID] = @OrderID, [Title] = @Title, [Start] = @Start, [End] = @End, [PercentComplete] = @PercentComplete, [Expanded] = @Expanded, [Summary] = @Summary WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ParentID" Type="Int32" />
            <asp:Parameter Name="OrderID" Type="Int32" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Start" Type="DateTime" />
            <asp:Parameter Name="End" Type="DateTime" />
            <asp:Parameter Name="PercentComplete" Type="Decimal" />
            <asp:Parameter Name="Expanded" Type="Boolean" />
            <asp:Parameter Name="Summary" Type="Boolean" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ParentID" Type="Int32" />
            <asp:Parameter Name="OrderID" Type="Int32" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Start" Type="DateTime" />
            <asp:Parameter Name="End" Type="DateTime" />
            <asp:Parameter Name="PercentComplete" Type="Decimal" />
            <asp:Parameter Name="Expanded" Type="Boolean" />
            <asp:Parameter Name="Summary" Type="Boolean" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </sds:SessionDataSource>

    <sds:SessionDataSource ID="DependenciesDataSource" runat="server" DisplayWarning="false"
        PrimaryKeyFields="ID" ProviderName="System.Data.SqlClient" 
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        DeleteCommand="DELETE FROM [GanttDependencies] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [GanttDependencies] ([PredecessorID], [SuccessorID], [Type]) VALUES (@PredecessorID, @SuccessorID, @Type)"
        SelectCommand="SELECT * FROM [GanttDependencies]"
        UpdateCommand="UPDATE [GanttDependencies] SET [PredecessorID] = @PredecessorID, [SuccessorID] = @SuccessorID, [Type] = @Type WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="PredecessorID" Type="Int32" />
            <asp:Parameter Name="SuccessorID" Type="Int32" />
            <asp:Parameter Name="Type" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="PredecessorID" Type="Int32" />
            <asp:Parameter Name="SuccessorID" Type="Int32" />
            <asp:Parameter Name="Type" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </sds:SessionDataSource>

   <asp:SqlDataSource runat="server" ID="ResourcesDataSource" 
       SelectCommand="SELECT * FROM [GanttResources]" 
       ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" />

    <sds:SessionDataSource ID="AssignmentsDataSource" runat="server" DisplayWarning="false"
        PrimaryKeyFields="ID" ProviderName="System.Data.SqlClient" 
        ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        DeleteCommand="DELETE FROM [GanttResourceAssignments] WHERE [ID] = @ID"
        InsertCommand="INSERT INTO [GanttResourceAssignments] ([TaskID], [ResourceID], [Units]) VALUES (@TaskID, @ResourceID, @Units)"
        SelectCommand="SELECT * FROM [GanttResourceAssignments]"
        UpdateCommand="UPDATE [GanttDependencies] SET [TaskID] = @TaskID, [ResourceID] = @ResourceID, [Units] = @Type WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
           
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ID" Type="Int32" />
            <asp:Parameter Name="TaskID" Type="Int32" />
            <asp:Parameter Name="ResourceID" Type="Int32" />
            <asp:Parameter Name="Units" Type="Decimal" />
        </UpdateParameters>
    </sds:SessionDataSource>

    </form>
</body>
</html>

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?