RadGrid OnDeleteCommand mapped to multiple gridcolumns

7 posts, 2 answers
  1. Prabal
    Prabal avatar
    4 posts
    Member since:
    Oct 2013

    Posted 21 Oct 2013 Link to this post

    I have 2 GridButtonColumns mapped to distinct Items..  a hyperlink Activate/De-Activate and and the 2nd item contains an imageButton for Delte both of which map to CommandName="Delete". In the OnDeleteCommand handler for the grid in the code behind how do I distinguish the GridEditableItem ImageButton with uniqueName="Delete" from trhe hyperlink with UniqueName="De-Activate" ?  I have tried retrieving sender.Gettype.Name and some other ways but do not see a straightforward way to tell which control sent the Delete Command in the handler. Please provide some insight at the earliest. Version used is 2010.35... etc.


    <telerik:GridButtonColumn CommandName="Delete" HeaderText="" UniqueName="De-Activate"
                                    HeaderStyle-Width="80px" ConfirmDialogType="Classic">
                                </telerik:GridButtonColumn>
                                 <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" ButtonType="ImageButton"
                                    UniqueName="Delete" Text="Delete" HeaderStyle-Width="80px" ConfirmDialogType="Classic">
                                </telerik:GridButtonColumn>
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2013 Link to this post

    Hi Prabal,

    In order to identify which button click,you can use the CommandArgument for the buttons.

    ASPX:
    <telerik:GridButtonColumn CommandName="Delete" UniqueName="De-Activate" CommandArgument="De-Activate" . . .>
    </telerik:GridButtonColumn>
    <telerik:GridButtonColumn CommandName="Delete" CommandArgument="Delete" UniqueName="Delete"  . . . . >
    </telerik:GridButtonColumn>

    C#:
    protected void DeleteCommand(object source, GridCommandEventArgs e)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        if (e.CommandArgument == "De-Activate")
        {
           //Code
        }
        else if(e.CommandArgument == "Delete")
        {
          //Code
        }
    }

    Thanks,
    Princy
  3. Prabal
    Prabal avatar
    4 posts
    Member since:
    Oct 2013

    Posted 22 Oct 2013 Link to this post

    Thanks Princy.. I'll let you know if that works out shortly.
  4. Prabal
    Prabal avatar
    4 posts
    Member since:
    Oct 2013

    Posted 22 Oct 2013 Link to this post

    If I don't put a commandargument for De-Activate in the code behind what is the default e.commandargument value when none exist? Do i check for it=null first?
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2013 Link to this post

    Hi Prabal,

    If you don't set any value for the CommandArgument, by default it's empty.You may check the condition as follows:

    C#:
    if (e.CommandArgument == "")
    {
    //Your Code
    }

    Thanks,
    Princy
  6. Prabal
    Prabal avatar
    4 posts
    Member since:
    Oct 2013

    Posted 31 Oct 2013 Link to this post

    <telerik:RadGrid ID="rgConveyanceFilters" runat="server" AutoGenerateColumns="false" AllowSorting="true" Visible="false"
                        GridLines="Both" OnNeedDataSource="rgConveyanceFilters_OnNeedDataSource" OnItemDataBound="rgConveyanceFilters_OnItemDataBound"
                        Width="600px" OnUpdateCommand="rgConveyanceFilters_OnUpdateCommand" OnInsertCommand="rgConveyanceFilters_OnInsertCommand"
                        OnDeleteCommand="rgConveyanceFilters_OnDeleteCommand">
     
     
    <telerik:GridButtonColumn CommandName="Delete" HeaderText="" UniqueName="De-Activate"
                                    HeaderStyle-Width="80px" ConfirmDialogType="Classic">
                                </telerik:GridButtonColumn>
                                <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" ButtonType="ImageButton"
                                    UniqueName="Delete" CommandArgument="DeleteFilter" HeaderStyle-Width="80px" ConfirmDialogType="Classic">
                                </telerik:GridButtonColumn>
    that worked out well.. I have another related question about custom commands. Can I have a custom Command="DeActivate" instead of mapping both my Delete and DeActivate to OnDeleteCommandName thru CommandName="Delete" in gridbuttoncolumn. Essentially is there a way to add custom commands besides the OnInsert/DeleteCommand and various others provided. If so how so that the code behind works seamlessly with it?
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Nov 2013 Link to this post

    Hi Prabal,

    You can have custom CommandName for the GridButtonColumn, like CommandName="DeActivate" , but it can be obtained only through the OnItemCommand of the RadGrid. To know about commands that invoke the Rebind() implicitly, have a look into this documentation, such commands can be obtained at their respective events. For custom CommandName please do the following:

    C#:
    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == "DeActivate")
        {
          //Code to delete
        }
    }

    Thanks,
    Princy



Back to Top