Hello --
I have a custom task class and a custom provider (non-EM). Both follow the model code, and work perfectly on page load.
When changing values, the server side TaskUpdate event fires, and e.Tasks(0) has the expected values for the task that was just updated.
However...
Problem 1: e.Tasks(0) is a standard Task object, and not my CustomTask object. How can I get my custom field values on TaskUpdate?
Problem 2: Sender, while containing the appropriate RadGantt properties set on the .aspx page, does not have the Provider I gave it on Page Load. Also, Tasks contains zero object and GetAllTasks returns nothing.
I'm not sure what code will help, so I'll just post it all. Sorry for the length.
Gantt declaration on the .aspx:
<telerik:RadAjaxManager runat="server" EnableAJAX="true" ></telerik:RadAjaxManager>
<telerik:RadAjaxPanel runat="server" >
<telerik:RadGantt runat="server" RenderMode="Auto" ID="RadGantt1" Enabled="true" Visible="true"
Skin="BlackMetroTouch" Height="600" Width="100%" ListWidth="60%"
AllowColumnResize="true" AllowSorting="true" ReadOnly="false" ShowTooltip="false"
EnablePdfExport="true" AutoGenerateColumns="false" DisplayDeleteConfirmation="true"
AllowPercentCompleteDrag="false" ShowCurrentTimeMarker="true" EnableViewState="true"
SelectedView="WeekView" WeekView-UserSelectable="true" YearView-UserSelectable="true"
DayView-UserSelectable="true" MonthView-UserSelectable="true">
<Columns>
<telerik:GanttBoundColumn DataField="Title" DataType="String" Width="180px" />
<telerik:GanttBoundColumn DataField="Start" DataType="DateTime" DataFormatString="dd/MM/yy" Width="80px" />
<telerik:GanttBoundColumn DataField="End" DataType="DateTime" DataFormatString="dd/MM/yy" Width="80px" />
<telerik:GanttBoundColumn DataField="System" HeaderText="System" DataType="String" Width="120px" />
<telerik:GanttBoundColumn DataField="ActivityType" HeaderText="Type" DataType="String" Width="120px" />
<telerik:GanttBoundColumn DataField="AssignedTo" HeaderText="AssignedTo" DataType="String" Width="120px" />
<telerik:GanttBoundColumn DataField="NotificationAddress" HeaderText="Notify" DataType="String" Width="250px" />
<telerik:GanttBoundColumn DataField="Description" HeaderText="Description" DataType="String" Width="300px" />
</Columns>
<CustomTaskFields>
<telerik:GanttCustomField PropertyName="Description" ClientPropertyName="description" Type="String" />
<telerik:GanttCustomField PropertyName="AssignedTo" ClientPropertyName="assignedTo" Type="String" />
<telerik:GanttCustomField PropertyName="System" ClientPropertyName="system" Type="String" />
<telerik:GanttCustomField PropertyName="ActivityType" ClientPropertyName="activityType" Type="String" />
<telerik:GanttCustomField PropertyName="NotificationAddress" ClientPropertyName="notificationAddress" Type="String" />
</CustomTaskFields>
<DataBindings>
<TasksDataBindings IdField="ID" ParentIdField="ParentID" StartField="Start" EndField="End" TitleField="Title" PercentCompleteField="PercentComplete" SummaryField="Summary" ExpandedField="Expanded" OrderIdField="OrderID" />
<DependenciesDataBindings TypeField="Type" IdField="ID" PredecessorIdField="PredecessorID" SuccessorIdField="SuccessorID" />
</DataBindings>
</telerik:RadGantt>
</telerik:RadAjaxPanel>
The page code-behind:
Private Sub RadGantt1_TaskUpdate(sender As Object, e As TaskEventArgs) Handles RadGantt1.TaskUpdate
' Both sender and RadGantt1 have no tasks here!
'e.Tasks(0) is a standard Task object. How can I get my custom column data?
End Sub
Lastly, sorry for the huge clip, but I don't know what could be significant.
Here's the custom provider. It seems to work fine.
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports Telerik.Web.UI.Gantt
Public Class CustomTask
Inherits Task
Public Sub New()
MyBase.New()
End Sub
Public Property Description() As String
Get
Return DirectCast(If(ViewState("Description"), ""), String)
End Get
Set(value As String)
ViewState("Description") = value
End Set
End Property
Public Property AssignedTo() As String
Get
Return DirectCast(If(ViewState("AssignedTo"), ""), String)
End Get
Set(value As String)
ViewState("AssignedTo") = value
End Set
End Property
Public Property System() As String
Get
Return DirectCast(If(ViewState("System"), ""), String)
End Get
Set(value As String)
ViewState("System") = value
End Set
End Property
Public Property RunActivityID() As Integer
Get
Return DirectCast(If(ViewState("RunActivityID"), ""), Integer)
End Get
Set(value As Integer)
ViewState("RunActivityID") = value
End Set
End Property
Public Property ActivityType() As String
Get
Return DirectCast(If(ViewState("ActivityType"), ""), String)
End Get
Set(value As String)
ViewState("ActivityType") = value
End Set
End Property
Public Property NotificationAddress() As String
Get
Return DirectCast(If(ViewState("NotificationAddress"), ""), String)
End Get
Set(value As String)
ViewState("NotificationAddress") = value
End Set
End Property
Public Property ScheduleDays() As String
Get
Return DirectCast(If(ViewState("ScheduleDays"), ""), String)
End Get
Set(value As String)
ViewState("ScheduleDays") = value
End Set
End Property
Protected Overrides Function GetSerializationData() As IDictionary(Of String, Object)
Dim dict = MyBase.GetSerializationData()
dict("Description") = Description
dict("AssignedTo") = AssignedTo
dict("System") = System
dict("RunActivityID") = RunActivityID
dict("ActivityType") = ActivityType
dict("NotificationAddress") = NotificationAddress
dict("ScheduleDays") = ScheduleDays
Return dict
End Function
Public Overrides Sub LoadFromDictionary(values As System.Collections.IDictionary)
MyBase.LoadFromDictionary(values)
Description = DirectCast(values("Description"), String)
AssignedTo = DirectCast(values("AssignedTo"), String)
System = DirectCast(values("System"), String)
RunActivityID = DirectCast(values("RunActivityID"), Integer)
ActivityType = DirectCast(values("ActivityType"), String)
NotificationAddress = DirectCast(values("NotificationAddress"), String)
ScheduleDays = DirectCast(values("ScheduleDays"), String)
End Sub
End Class
Public Class CustomGanttTaskFactory
Implements ITaskFactory
Private Function ITaskFactory_CreateTask() As Task Implements ITaskFactory.CreateTask
Return New CustomTask()
End Function
End Class
Public Class GanttCustomProvider
Inherits GanttProviderBase
Private TemplateName As String
Private RunID As Integer
Private ProcString As String 'all three of these are used to help form the SQL queries
Public Sub New()
MyBase.New()
End Sub
Public Sub New(Template As String)
MyBase.New()
TemplateName = Template
ProcString = "@TemplateName = '" & TemplateName & "'"
End Sub
Public Sub New(SandboxRunID As Integer)
MyBase.New()
RunID = SandboxRunID
ProcString = "@RunID = " & SandboxRunID.ToString
End Sub
Public Overrides ReadOnly Property TaskFactory() As ITaskFactory
Get
Return New CustomGanttTaskFactory()
End Get
End Property
Public Overrides Function GetTasks() As List(Of ITask)
Dim tasks = New List(Of ITask)()
Dim strConn As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmdCommand As SqlCommand = conn.CreateCommand()
cmdCommand.CommandText = "usp_Telerik_Task_SELECT " & ProcString
cmdCommand.CommandType = System.Data.CommandType.Text
conn.Open()
Dim dr As SqlDataReader = cmdCommand.ExecuteReader()
If dr.HasRows Then
While dr.Read()
Dim newTask As New CustomTask
newTask.ID = dr("ID")
newTask.ParentID = dr("ParentID")
newTask.OrderID = dr("OrderID")
newTask.Title = dr("Title")
newTask.Start = dr("Start")
newTask.End = dr("End")
newTask.PercentComplete = dr("PercentComplete")
newTask.Expanded = dr("Expanded")
newTask.Summary = dr("Summary")
newTask.Description = dr("Description")
newTask.AssignedTo = dr("Assigned To")
newTask.System = dr("StageID").ToString()
newTask.RunActivityID = dr("RunActivityID")
newTask.ActivityType = dr("ActivityType")
newTask.NotificationAddress = dr("Notification Address")
newTask.ScheduleDays = dr("ScheduleDays")
tasks.Add(newTask)
End While
End If
tasks(0).ParentID = Nothing
tasks(0).Summary = True
Return tasks
End Function
Public Overrides Function UpdateTask(task As ITask) As ITask
Dim strConn As String
Dim sqlText As String = "usp_Telerik_Task_UPDATE "
sqlText = sqlText & "@ID = " & task.ID.ToString
sqlText = sqlText & ", @ParentID = " & task.ParentID.ToString
sqlText = sqlText & ", @OrderID = " & task.OrderID.ToString
sqlText = sqlText & ", @Title = '" & task.Title & "'"
sqlText = sqlText & ", @Start = '" & task.Start.ToString & "'"
sqlText = sqlText & ", @End = '" & task.End.ToString & "'"
sqlText = sqlText & ", @PercentComplete = " & task.PercentComplete.ToString
sqlText = sqlText & ", @Expanded = " & task.Expanded.ToString()
sqlText = sqlText & ", @Summary = " & task.Summary.ToString()
' comment out these lines because only a standard task is provided by the control and the custom fields are not included.
'sqlText = sqlText & ", @StageName = '" & task.StageName & "'"
'sqlText = sqlText & ", @ActivityType = '" & task.ActivityType.ToString & "'"
'sqlText = sqlText & ", @NotificationAddress = '" & task.NotificationAddress.ToString & "'"
'sqlText = sqlText & ", @ScheduleDays = '" & task.ScheduleDays.ToString & "'"
'sqlText = sqlText & ", @Comments = '" & task.Description.ToString & "'"
strConn = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmdCommand As SqlCommand = conn.CreateCommand()
cmdCommand.CommandText = sqlText
cmdCommand.CommandType = System.Data.CommandType.Text
conn.Open()
cmdCommand.ExecuteNonQuery()
Return task
End Function
Public Overrides Function DeleteTask(task As ITask) As ITask
' not implemented yet
Return task
End Function
Public Overrides Function InsertTask(task As ITask) As ITask
' not implemented yet
Return task
End Function
Public Overrides Function GetDependencies() As List(Of IDependency)
Dim deps = New List(Of IDependency)()
Dim strConn As String
strConn = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmdCommand As SqlCommand = conn.CreateCommand()
cmdCommand.CommandText = "usp_Telerik_TaskDependencies_SELECT " & ProcString
cmdCommand.CommandType = System.Data.CommandType.Text
conn.Open()
Dim dr As SqlDataReader = cmdCommand.ExecuteReader()
If dr.HasRows Then
While dr.Read()
Dim newDep As New Dependency
newDep.ID = dr("ID")
newDep.PredecessorID = dr("PredecessorID")
newDep.SuccessorID = dr("SuccessorID")
newDep.Type = dr("Type")
deps.Add(newDep)
End While
End If
Return deps
End Function
Public Overrides Function DeleteDependency(dependency As IDependency) As IDependency
' not implemented yet
Return dependency
End Function
Public Overrides Function InsertDependency(dependency As IDependency) As IDependency
' not implemented yet
Return dependency
End Function
End Class