Get Selected TaskId _OnTaskDelete

6 posts, 1 answers
  1. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 06 Nov 2015 Link to this post

    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;
        }

  2. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 11 Nov 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 11 Nov 2015 in reply to Bozhidar Link to this post

    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,

     ​

  5. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 12 Nov 2015 Link to this post

    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
  6. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 12 Nov 2015 in reply to Bozhidar Link to this post

    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!

  7. Julian
    Julian avatar
    54 posts
    Member since:
    Apr 2015

    Posted 10 Dec 2015 Link to this post

    This worked thank you!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017