Search code examples
c#onclickimagebuttontelerik-grid

OnItemCommand Doesn't Work on Telerik Grid


I'm trying to create a Telerik grid where one of the columns contain a button that clicking it performs a certain action. This is my definition of the grid in ASP:

<sq:Grid runat="server" CssClass="Master" ID="ReportGrid" DataSourceID="WorkPackageDS" 
           CellSpacing="0" GridLines="None" PageSize="100" AllowSorting="True" OnItemCommand="CancelWorkPackage_OnItemCommand"
           AllowCustomPaging="True" AutoGenerateColumns="False" EnableViewState="False">

And this is the button I added:

<sq:GridTemplateColumn FilterImageToolTip="סינון" HeaderText="ביטול חבילת עבודה" UniqueName="btnCancelWO">
  <ItemTemplate>
    <asp:ImageButton runat="server" ID="btnCancel" ImageUrl="~/Shared Resources/imaes/tasksButton.png" 
                     CommandName="CancelWO" CssClass="GridImageButton">
    </asp:ImageButton>
  </ItemTemplate>
</sq:GridTemplateColumn>

The "sq" is just something in my company, but it means a Telerik object. This is my C# code of the function:

public void CancelWorkPackage_OnItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "CancelWO")
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem gridDataItem = e.Item as GridDataItem;

                string WFGUI = gridDataItem.FindControl("GUI").ToString();
                int WorkflowInstanceId = Int32.Parse(gridDataItem.FindControl("fldIWfId").ToString());

                RoadsManager.Instance.CancelWorkPackage(WFGUI, WorkflowInstanceId);
                RoadsManager.Instance.LogCancellation(new[] { WorkflowInstanceId }, CurrentActivityId, CurrentUserId);
                SignManager.Instance.DownloadPermitsFromSSRS(WorkflowInstanceId, WorkflowAPI.Instance.GetWorkflowVariable<object>(WorkflowInstanceId, "ReportName").ToString());
                ShowAlert("חבילת עבודה ואישורים בוטלו בהצלחה", 400, 150, "הודעה חשובה");
            }
        }
    }

I added breakpoint in the beginning of the C# function (on the if) and the program doesn't even enter the function. What am I doing wrong? Can anyone give me a tip what to change? Thank you in advance


Solution

  • I changed the entire column from GridTemplateColumn to GridButtonColumn and now it works fine.