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

How to trigger OnBatchEditCommand event from CommandItemTemplate?

2 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fahd
Top achievements
Rank 1
fahd asked on 29 Oct 2014, 01:14 PM
I have custom actions that I need to perform on a grid, so I can't use the built-in item commands "Update and Cancel" which trigger the OnBatchEditCommand correctly. As soon as I use CommandItemTemplate tags, I lose that functionality which triggers the OnItemCommand. In code behind, the e.CommandArgument of the OnItemCommand is empty so I can't get a handle on the old and new values to perform tasks.

Please help.

Thanks,
Fahd

2 Answers, 1 is accepted

Sort by
0
fahd
Top achievements
Rank 1
answered on 29 Oct 2014, 02:48 PM
To make the problem more apparent, below is the code snippet of the markup. When I press the update button, the ItemCommand gets triggered without the CommandArgument property. How can I trigger the OnBatchEditCommand using CommandItemTemplate?

01.<telerik:RadGrid ID="rgBatchEditing" runat="server" GridLines="Horizontal"
02.    AllowMultiRowSelection="true" AllowSorting="true" AllowPaging="true" AutoGenerateColumns="false"
03.    PageSize="15" Skin="View"
04.    OnBatchEditCommand="rgBatchEditing_BatchEditCommand"
05.    OnNeedDataSource="rgBatchEditing_NeedDataSource"
06.    OnItemCommand="rgBatchEditing_ItemCommand">
07.    <ClientSettings AllowKeyboardNavigation="true">
08.        <Selecting AllowRowSelect="true" EnableDragToSelectRows="false"/>
09.    </ClientSettings>
10.    <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="Individual,Registration,SignInTime1,SignOutTime1"
11.        EditMode="Batch" AutoGenerateColumns="False" AllowMultiColumnSorting="true">
12.        <CommandItemSettings ShowAddNewRecordButton="false"  />
13.        <RowIndicatorColumn UniqueName="ClientSelectColumn">
14.            <HeaderStyle Width="25" />
15.        </RowIndicatorColumn>
16.        <BatchEditingSettings EditType="Row" />
17.        <Columns>
18.            <telerik:GridClientSelectColumn UniqueName="SelectorColumn">
19.            <HeaderStyle Width="20px" />
20.            <ItemStyle  HorizontalAlign="Left"/>
21.            </telerik:GridClientSelectColumn>
22.            <telerik:GridTemplateColumn HeaderText="Individual" UniqueName="Individual" DataField="Individual" SortExpression="Individual">
23.                <ItemTemplate>
24.                    <asp:Label ID="lblIndividual" runat="server" Text="<%# ((PLI.WMS.Business.Entity.Att)Container.DataItem).Individual %>"></asp:Label>
25.                </ItemTemplate>
26.                <HeaderStyle Width="70" />
27.            </telerik:GridTemplateColumn>
28.            <telerik:GridTemplateColumn HeaderText="First Name" SortExpression="FirstName" UniqueName="FirstName">
29.                    <ItemTemplate>
30.                        <asp:Label ID="lbFirstName" runat="server" Text="<%# ((PLI.WMS.Business.Entity.Att)Container.DataItem).FirstName %>"></asp:Label>
31.                    </ItemTemplate>
32.                    <HeaderStyle Width="100" />
33.                    <ItemStyle Height="25" />
34.                </telerik:GridTemplateColumn>
35.                <telerik:GridTemplateColumn HeaderText="Last Name" SortExpression="LastName" UniqueName="LastName">
36.                    <ItemTemplate>
37.                        <asp:Label ID="lbLastName" runat="server" Text="<%# ((PLI.WMS.Business.Entity.Att)Container.DataItem).LastName %>"></asp:Label>
38.                    </ItemTemplate>
39.                    <HeaderStyle Width="100" />
40.                    <ItemStyle Height="25" />
41.                </telerik:GridTemplateColumn>
42.            <telerik:GridTemplateColumn DataField="Registration" HeaderText="Registration" SortExpression="Registration"
43.                UniqueName="RegistrationID">
44.                <ItemTemplate>
45.                    <asp:Label ID="lblRegistration" runat="server" Text="<%# ((PLI.WMS.Business.Entity.Att)Container.DataItem).Registration %>"></asp:Label>
46.                </ItemTemplate>
47.                <HeaderStyle Width="80" />
48.            </telerik:GridTemplateColumn>
49.        </Columns>
50.        <CommandItemTemplate>
51.        <div style="width:100%;">
52.                    <span style="display:block;float:left;">
53.                        <asp:LinkButton ID="lnkUpdateEdited" runat="server" CommandName="UpdateEdited" Width="120">
54.                            <img style="border:0px;vertical-align:middle; height:24px;" alt="" src="../Images/update.png"/><b style="padding-left:5px;">Update</b>
55.                        </asp:LinkButton>
56.                    </span>
57.                    <span style="display:block;float:left;">
58.                        <asp:LinkButton ID="lnkCancel" runat="server" CommandName="CancelAll" Width="120">
59.                            <img style="border:0px;vertical-align:middle;" alt="" src="../Images/cancel.png"/><b style="padding-left:5px;">Cancel editing</b>
60.                        </asp:LinkButton>
61.                    </span>
62.                    <span style="display:block;float:left;">                                                           
63.                            <asp:LinkButton ID="lnkCustomAction" runat="server" CommandName="cmdCustomAction" Width="120">
64.                                <img alt="Perform custom action" src="../Images/CustomAction.png" border="0"/><b style="padding-left:5px;">Custom Action</b>
65.                            </asp:LinkButton>
66.                    </span>
67.                    </div>
68.        </CommandItemTemplate>
69.    </MasterTableView>
70.</telerik:RadGrid>
0
fahd
Top achievements
Rank 1
answered on 29 Oct 2014, 04:26 PM
I finally got it to work by using Client-side GridBatchEditing API. Though, we need to stop the execution by returning true otherwise it will not work.

Javascript:
1.function SaveChangesInGrid(sender, args) {
2.    var grid = $find('<%=rgBatchEditing.ClientID%>');
3.    grid.get_batchEditingManager().saveChanges(grid.get_masterTableView());
4.    return true;
5.}


Markup:
1.<CommandItemTemplate>
2.       <asp:LinkButton ID="lnkUpdateEdited" runat="server" CommandName="UpdateEdited" Width="120" OnClientClick="if(SaveChangesInGrid()) {return false;}">
3.    <img style="border:0px;vertical-align:middle; height:24px;" alt="" src="../Images/update.png"/><b style="padding-left:5px;">Update</b>
4.    </asp:LinkButton>
5.</CommandItemTemplate>

Hope this helps.
Tags
Grid
Asked by
fahd
Top achievements
Rank 1
Answers by
fahd
Top achievements
Rank 1
Share this question
or