This is a migrated thread and some comments may be shown as answers.

Get Selected TaskId _OnTaskDelete

5 Answers 53 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 06 Nov 2015, 08:44 PM

I have a radGantt utilizing a custom C# provider. If i select a task in the gantt chart on the left and hit the delete key the code triggers the following server side event..

 

protected void radGanttPlanning_OnTaskDelete(object sender, TaskEventArgs e)
        {​

 

In this section of code in the code behind  how would i obtain the currently selected taskId of the task I need to delete?

 

Here is the custom provider's getTask method just to show you the structure of the CustomTask should you need it. 

public override List<ITask> GetTasks()
    {
        if (taskList == null)
        {
         
            List<CurrencyRates> lsCurrencyRates = CurrencyRate.GetEffectiveCurrencyRates();
            var tasks = (from DataRow drDataRow in dtResultTable.Rows
                select new CustomTask
                {
                    DatabaseID = int.Parse(drDataRow["id"].ToString()),
                    ID = drDataRow["projecttaskid"].ToString(),
                    ParentID = (drDataRow["parentId"] == DBNull.Value) ? null : drDataRow["parentId"],
                    OrderID = int.Parse(drDataRow["OrderId"].ToString()),
                    Start = DateTime.Parse(drDataRow["startdate"].ToString()),
                    End = DateTime.Parse(drDataRow["enddate"].ToString()),
                    Summary = bool.Parse(drDataRow["issummarytask"].ToString()),
                    Title = drDataRow["taskname"].ToString(),
                    Active = bool.Parse(drDataRow["active"].ToString()),
                    PreferredStart = DateTime.Parse(drDataRow["preferredstartdate"].ToString()),
                    Expanded = bool.Parse(drDataRow["expandable"].ToString()),
                    PercentComplete = (Decimal.Parse(drDataRow["percentageComplete"].ToString())/100),
                    ProjectID = int.Parse(drDataRow["projectid"].ToString()),
                    GuidID = Guid.Parse(drDataRow["guidid"].ToString()),
                    PredecessorIndicies = drDataRow["predecessorIndicies"].ToString(),
                    SchedulingGranularity = int.Parse(drDataRow["schedulingGranularity"].ToString()),
                    IndentLevel = int.Parse(drDataRow["indentlevel"].ToString()),
                    //Effort = int.Parse(drDataRow["effort"].ToString()),
                    TotalActualHours = double.Parse(drDataRow["TotalActualHours"].ToString()),
                    IsVave = bool.Parse(drDataRow["projectisvave"].ToString()),
                    lsCurrencyRates = lsCurrencyRates
                }).Cast<ITask>().ToList();

            taskList = tasks;
        }
        return taskList;
    }

5 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 11 Nov 2015, 08:13 AM
Hello,

The tasks that are going to be deleted are passed in the TaskEventArgs paramether. You can obtain each ID with the following code:
protected void RadGantt1_TaskDelete(object sender, TaskEventArgs e)
{
    foreach (var task in e.Tasks)
    {
        var id = task.ID;
    }
}


Regards,
Bozhidar
Telerik
0
Julian
Top achievements
Rank 1
answered on 11 Nov 2015, 03:14 PM

I'm sorry Bozhidar but what I was asking , very poorly, was how to obtain the TaskID outside of telerik's event that is triggered when you click delete on a task inside the Gantt control. Say I have a button outside of the control such as:

 

<button type="button" data-toggle="tooltip" id="btnDeleteCurrentTask" OnServerClick="btnDeleteCurrentTask_OnServerClick" runat="server" title="Delete Current Task" class="glyphicon btn-success glyphicon glyphicon-minus"></button>

Inside of this method "btnDeleteCurrentTask_OnServerClick", how would I go about obtaining the Gantt's currently selected task's ID?

 

Thanks,

 ​

0
Accepted
Bozhidar
Telerik team
answered on 12 Nov 2015, 09:23 AM
Hi,

Thank you for the clarification. 

You could use the client click event of the button to store the selected ID in a hiddenfield, and then on the server get the HiddenFieldValue. Here's some sample code:
<script type="text/javascript">
 
    function storeSelectedID() {
        var $ = $telerik.$;
        var gantt = $find("RadGantt1");
        var uid = gantt._widget.select().attr("data-uid");
 
        var task = gantt.get_allTasks().find(function(task) { return task._uid == uid; });
 
        $get("HiddenField1").value = task.get_id();
    }
 
</script>
 
<div>
 
    <telerik:RadGantt runat="server" ID="RadGantt1" >
        <WebServiceSettings Path="GanttService.asmx" />
    </telerik:RadGantt>
 
    <asp:HiddenField runat="server" ID="HiddenField1" />
 
    <button id="Button1" runat="server" onserverclick="Button1_ServerClick" onclick="storeSelectedID();" title="Delete" type="button">Hide</button>
 
    <asp:Label ID="Label1" Text="text" runat="server" />
</div>
protected void Button1_ServerClick(object sender, EventArgs e)
{
    Label1.Text = HiddenField1.Value;
}


Regards,
Bozhidar
Telerik
0
Julian
Top achievements
Rank 1
answered on 12 Nov 2015, 02:14 PM

Thank you Bozhidar. That looks about like what I thought as far as where I needed to go I'll use this and see where I get and post back.

 Thanks!

0
Julian
Top achievements
Rank 1
answered on 10 Dec 2015, 03:18 PM
This worked thank you!
Tags
Gantt
Asked by
Julian
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Julian
Top achievements
Rank 1
Share this question
or