Hello,
I have added One Custom Task Field 'SrNo' as object datatype with respect to demo project given here. I have not used EntityFramework. I am Binding RadGantt's Datasource and DependenciesDataSource simply on Page_Load Event.
To add new Task Field below is the code I have written
public
class
CustomGanttTaskFactory : ITaskFactory
{
Task ITaskFactory.CreateTask()
{
return
new
CustomTask();
}
}
public
class
CustomTask : Task
{
public
CustomTask()
:
base
()
{
}
public
object
SrNo
{
get
{
return
(
object
)(ViewState[
"SrNo"
] ??
""
); }
set
{ ViewState[
"SrNo"
] = value; }
}
protected
override
IDictionary<
string
,
object
> GetSerializationData()
{
var dict =
base
.GetSerializationData();
dict[
"SrNo"
] = SrNo;
return
dict;
}
public
override
void
LoadFromDictionary(System.Collections.IDictionary values)
{
base
.LoadFromDictionary(values);
SrNo = values[
"SrNo"
];
}
}
Page_Load Event:
protected
void
Page_Load(
object
sender, EventArgs e)
{
List<ITask> newFinalTask =
new
List<ITask>();
List<IDependency> FinalDependency =
new
List<IDependency>();
newFinalTask.Add(
new
CustomTask { ID = 1, SrNo =
"1"
, OrderID = 1, ParentID =
null
, Title =
"A"
, Start =
new
DateTime(2015, 01, 10, 0, 0, 0), End =
new
DateTime(2015, 01, 19, 23, 59, 59), PercentComplete = 0.60M, Expanded =
false
, Summary =
true
});
newFinalTask.Add(
new
CustomTask { ID = 2, SrNo =
""
, OrderID = 2, ParentID = 1, Title =
"A1"
, Start =
new
DateTime(2015, 01, 10, 0, 0, 0), End =
new
DateTime(2015, 01, 15, 23, 59, 59), PercentComplete = 0.60M, Expanded =
false
});
newFinalTask.Add(
new
CustomTask { ID = 3, SrNo =
""
, OrderID = 3, ParentID = 1, Title =
"A2"
, Start =
new
DateTime(2015, 01, 16, 0, 0, 0), End =
new
DateTime(2015, 01, 19, 23, 59, 59), PercentComplete = 0.60M, Expanded =
false
});
newFinalTask.Add(
new
CustomTask { ID = 4, SrNo =
"2"
, OrderID = 4, ParentID =
null
, Title =
"B"
, Start =
new
DateTime(2015, 01, 20, 0, 0, 0), End =
new
DateTime(2015, 01, 31, 23, 59, 59), PercentComplete = 0.60M, Expanded =
false
, Summary =
true
});
newFinalTask.Add(
new
CustomTask { ID = 5, SrNo =
""
, OrderID = 5, ParentID = 4, Title =
"B1"
, Start =
new
DateTime(2015, 01, 20, 0, 0, 0), End =
new
DateTime(2015, 01, 31, 23, 59, 59), PercentComplete = 0.60M, Expanded =
false
});
FinalDependency.Add(
new
Dependency { ID = 1, PredecessorID = 1 ,SuccessorID = 4, Type = DependencyType.FinishStart });
RadGantt1.DataSource = newFinalTask;
RadGantt1.DependenciesDataSource = FinalDependency;
}
Design Page:
<
telerik:RadGantt
runat
=
"server"
ID
=
"RadGantt1"
Enabled
=
"true"
ReadOnly
=
"True"
AllowSorting
=
"False"
>
<
DataBindings
>
<
TasksDataBindings
IdField
=
"ID"
TitleField
=
"Title"
StartField
=
"Start"
EndField
=
"End"
PercentCompleteField
=
"PercentComplete"
OrderIdField
=
"OrderID"
SummaryField
=
"Summary"
ParentIdField
=
"ParentID"
/>
<
DependenciesDataBindings
IdField
=
"ID"
PredecessorIdField
=
"PredecessorID"
SuccessorIdField
=
"SuccessorID"
TypeField
=
"Type"
/>
</
DataBindings
>
<
CustomTaskFields
>
<
telerik:GanttCustomField
PropertyName
=
"SrNo"
ClientPropertyName
=
"SrNo"
/>
</
CustomTaskFields
>
<
Columns
>
<
telerik:GanttBoundColumn
DataField
=
"ID"
HeaderText
=
"ID"
AllowEdit
=
"false"
AllowSorting
=
"false"
Width
=
"50px"
></
telerik:GanttBoundColumn
>
<
telerik:GanttBoundColumn
DataField
=
"SrNo"
HeaderText
=
"Sr.No."
AllowEdit
=
"false"
AllowSorting
=
"false"
Width
=
"50px"
UniqueName
=
"SrNo"
></
telerik:GanttBoundColumn
>
<
telerik:GanttBoundColumn
DataField
=
"Title"
HeaderText
=
"ACTIVITY"
AllowEdit
=
"false"
AllowSorting
=
"false"
></
telerik:GanttBoundColumn
>
<
telerik:GanttBoundColumn
DataField
=
"Start"
HeaderText
=
"START"
DataFormatString
=
"dd/MM/yyyy"
AllowEdit
=
"false"
AllowSorting
=
"false"
Width
=
"80px"
></
telerik:GanttBoundColumn
>
<
telerik:GanttBoundColumn
DataField
=
"End"
HeaderText
=
"END"
DataFormatString
=
"dd/MM/yyyy"
AllowEdit
=
"false"
AllowSorting
=
"false"
Width
=
"80px"
></
telerik:GanttBoundColumn
>
<
telerik:GanttBoundColumn
DataField
=
"PercentComplete"
HeaderText
=
"% COMPLETED"
AllowEdit
=
"false"
AllowSorting
=
"false"
></
telerik:GanttBoundColumn
>
</
Columns
>
</
telerik:RadGantt
>
But it is not Displaying Data in Sr.No. Field. Below Attached is the output Image.
Please help me with what is wrong with my code.