telerik RadGantt来自Code背后的绑定

时间:2014-09-16 10:44:42

标签: c# asp.net telerik

我想从这里的代码绑定Telerik的Rad Gantt是我的代码:

 <telerik:RadGantt runat="server" ID="RadGantt1" Width="1275px" Height="600px" ListWidth="351px"
             SelectedView="WeekView" Skin="Silk" AutoGenerateColumns="false">
            <Columns>
                <telerik:GanttBoundColumn DataField="TaskName" DataType="String" Width="120px"></telerik:GanttBoundColumn>
                <telerik:GanttBoundColumn DataField="StartDate" DataType="DateTime" DataFormatString="dd/MM/yy" Width="40px"></telerik:GanttBoundColumn>
                <telerik:GanttBoundColumn DataField="EndDate" DataType="DateTime" DataFormatString="dd/MM/yy" Width="40px"></telerik:GanttBoundColumn>
            </Columns>    
               <DataBindings>
            <TasksDataBindings IdField="TaskID" ParentIdField="TaskID" StartField="StartDate" OrderIdField="TaskID" SummaryField="Summary" ExpandedField="Expanded" EndField="EndDate" TitleField="TaskName"
                PercentCompleteField="PercentComplete" />
            <DependenciesDataBindings TypeField="Type" IdField="TaskID" PredecessorIdField="TaskID" SuccessorIdField="TaskID" />
        </DataBindings>    
            </telerik:RadGantt>

并在代码中

RadGantt1.DataSource = Gatdata();
        RadGantt1.DataBind();

我在DataBind()上遇到此错误“DataSourceID在数据源绑定的情况下可能不为空”这里GetData()方法返回包含列和有效数据的非常简单的数据表

2 个答案:

答案 0 :(得分:0)

编辑:尝试最新的内部构建Telerik产品。重新阅读帖子后,我似乎误解了原来的问题。这似乎是一个错误或限制,因此它可能已经修复/改进。

答案 1 :(得分:0)

 <telerik:RadScriptManager ID="QsfScriptManager" runat="server"/>
     <telerik:RadGantt ID="RadGantt1" runat="server"  ReadOnly="false" SelectedView="WeekView" Width="100%" ListWidth="351px"
         Skin="Silk">
        <DataBindings>
            <TasksDataBindings IdField="ID"  ParentIdField="ParentID" StartField="Start" OrderIdField="OrderID" SummaryField="Summary" ExpandedField="Expanded" EndField="End" TitleField="Title"
                PercentCompleteField="PercentComplete" />
            <DependenciesDataBindings TypeField="Type" IdField="ID" PredecessorIdField="PredecessorID"   SuccessorIdField="SuccessorID" />
        </DataBindings>
    </telerik:RadGantt>

cs.file

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString.ToString());

    conn.Open();
    SqlDataAdapter adapter;
    DataTable dt = new DataTable();

    adapter = new SqlDataAdapter("SELECT * FROM GanttTasks", conn);
    adapter.Fill(dt);

    SqlDataSource2.ConnectionString = ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString.ToString();
    SqlDataSource2.SelectCommand = "SELECT * FROM GanttTasks";
    SqlDataSource2.DataBind();

    SqlDataSource4.ConnectionString = ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString.ToString();
    SqlDataSource4.SelectCommand = "SELECT * FROM GanttDependencies";
    SqlDataSource4.UpdateCommand = "UPDATE GanttDependencies SET PredecessorID = @PredecessorID, SuccessorID = @SuccessorID, Type = @Type WHERE ID = @ID";
    SqlDataSource4.DataBind();


    RadGantt1.DataSourceID = SqlDataSource2.ID;
    RadGantt1.DependenciesDataSourceID = SqlDataSource4.ID;

    conn.Close();