telerik RadGantt从代码后面绑定

本文关键字:绑定 代码 RadGantt telerik | 更新日期: 2023-09-27 18:21:58

我想从后面的代码绑定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()上遇到了这个错误"在DataSource绑定的情况下,DataSourceID可能不是null"这里GetData()方法返回非常简单的数据表,其中包含列和有效数据

telerik RadGantt从代码后面绑定

EDIT:试试Telerik最新的内部版本。重读这篇文章后,我似乎误解了原来的问题。这看起来像是一个错误或限制,所以它可能已经被修复/改进了。

 <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();