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

CommandItemSettings Show Update and Delete Buttons

11 Answers 695 Views
Grid
This is a migrated thread and some comments may be shown as answers.
APESTANA
Top achievements
Rank 2
APESTANA asked on 17 Aug 2012, 09:18 AM
Hi,
I was trying to use your CommandItemSettings to automatically display the Update and Delete buttons, like the AddNewRecordButton, but there is no such option available, I was wondering why? It would be useful to have those buttons available that would apply the command to the selected items in the grid, instead of having to add all to the CommandItemTemplate. These are common operations that one does in the grid...

Regards, Ariel

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Aug 2012, 09:39 AM
Hi,

You can customize the CommandItemDisplay to your own(insert,update,delete buttons) using CommandItemtemplate as follows.
aspx:
<MasterTableView Width="100%" CommandItemDisplay="Top" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID">
    <CommandItemTemplate>
       <div style="padding: 5px 5px;">
              Custom command item template    
         <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit selected</asp:LinkButton>  
       <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" />Update</asp:LinkButton>  
      <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 ||         RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" />
Cancel editing</asp:LinkButton>  
 <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted                %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/AddRecord.gif" />Add new</asp:LinkButton>  
     <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%#                RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Insert.gif" />                Add this Customer</asp:LinkButton>  
   <asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected customers?')"
runat="server" CommandName="DeleteSelected"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Delete.gif" />Delete selected customers</asp:LinkButton>  
            </div>
     </CommandItemTemplate>
</MasterTableView>

Also take a look into the following demo which explains the same scenario.
Grid / Command Item

Thanks,
Shinu.
0
APESTANA
Top achievements
Rank 2
answered on 17 Aug 2012, 10:06 AM
Hi, 
I know that I can do it like that, but my question was why the CommandItemSettings does not have the ShowEditRecordButton and ShowDeleteRecordButton?

Regards, Ariel.
0
Tsvetina
Telerik team
answered on 22 Aug 2012, 08:31 AM
Hi Ariel,

The default buttons contained in the GridCommandItem are such that apply to the whole grid, the Delete and Edit buttons are shown per row and that is why they are not added in the command item. We cannot know whether the requirement would be to delete a selected row (and if selection would be enabled at all), or to have the row marked differently for edit or delete.

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
João
Top achievements
Rank 1
answered on 08 Apr 2014, 05:40 PM
Hi,
i'm trying to implement a delete button in a RadGrid to do the following, after apply a filter I want to delete all records shown in the grid.
It's possible to do this? I haven't found a solution for this.
0
Princy
Top achievements
Rank 2
answered on 09 Apr 2014, 05:31 AM
Hi,

Please try the following code snippet to delete the items after filter.

ASPX:
<CommandItemTemplate>
    <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" />
</CommandItemTemplate>

C#:
static bool isFilter = false;
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        isFilter = true;
    }
    if (e.CommandName == "Delete" && isFilter == true)
    {
        foreach (GridDataItem items in RadGrid1.MasterTableView.Items)
        {
            string id = items.GetDataKeyValue("Id").ToString();
            //Code to delete
        }
    }
}

Thanks,
Princy
0
João
Top achievements
Rank 1
answered on 09 Apr 2014, 04:02 PM
Hi,
thanks for the response, but this only gets my first 10 rows because i'm using paging.
I don´t know how to get all the results :/

Best regards,
JD
0
Princy
Top achievements
Rank 2
answered on 10 Apr 2014, 06:26 AM
Hi,

You can cancel the Paging on delete command and set it again after deletion. Please try the following code snippet.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        isFilter = true;
    }
    if (e.CommandName == "Delete" && isFilter == true)
    {
        RadGrid1.AllowPaging = false;
        RadGrid1.Rebind();
        foreach (GridDataItem items in RadGrid1.MasterTableView.Items)
        {
            string id = items.GetDataKeyValue("Id").ToString();
            //Code to delete          
        }
        RadGrid1.AllowPaging = true;
        RadGrid1.Rebind();
    }
}

Thanks,
Princy
0
João
Top achievements
Rank 1
answered on 14 Apr 2014, 08:59 AM
Hi,

thanks for the help Princy, i have just only one more issue I can´t solve. Instead of using the <CommandItemTemplate> I want to use a <asp:LinkButton>, but I can´t put this to fire the event RadGrid1_ItemCommand!

Thanks,
JD
0
Princy
Top achievements
Rank 2
answered on 14 Apr 2014, 09:24 AM
Hi,

I guess you want to set asp:LinkButton instead of button in the CommandItemTemplate. Please make sure you have set the CommandName property for the LinkButton for the ItemCommand event to fire.

ASPX:
<CommandItemTemplate>
 <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete"> Delete</asp:LinkButton>
</CommandItemTemplate>

Thanks,
Princy
0
João
Top achievements
Rank 1
answered on 14 Apr 2014, 05:41 PM
No, what a want is a asp:Button or a asp:LinkButton to run the RadGrid1_ItemCommand method outside the CommandItemTemplate, is it possible?

Thanks,
JD
0
Princy
Top achievements
Rank 2
answered on 16 Apr 2014, 04:07 AM
Hi,

I'm afraid this is not possible. If you want the button in the CommandItem area, you have to use the CommandItemTemplate.The ItemCommand event is raised when a button is clicked in the Telerik RadGrid control. This allows you to provide an event-handling method that performs a custom routine whenever this event occurs.
Hope this helps you. Please let me know if any concern.

Thanks,
Princy
Tags
Grid
Asked by
APESTANA
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
APESTANA
Top achievements
Rank 2
Tsvetina
Telerik team
João
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or