RadGrid - "Row" Type DoubleClick BatchEdit, saveChanges command how to get data from grid?

8 posts, 0 answers
  1. sharon
    sharon avatar
    27 posts
    Member since:
    Jul 2015

    Posted 01 Jul 2015 Link to this post

     

    Hi!

       I use <telerik:RadGrid>, <BatchEditingSettings EditType="Row" OpenEditingEvent="DblClick" /> for data editing,

    My problem is when the saveChanges button being clicked, It triggered - BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e) event, however, (I referenced from searched samples) when trying to loop through and get data within the grid:

    foreach (GridBatchEditingCommand gridBECmd in e.Commands)

    {}

    the e.Commands.count is always 0, therefore, I couldn't get data to save. 

    Can anyone give any advises?

    thanks!

    Sharon

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2252 posts

    Posted 06 Jul 2015 Link to this post

    Hello Sharon,

    The behavior you describe seems rather strange. I tried to replicate it in a sample project, however, I was not able to. I am attaching the sample.

    Give it a try and see how it works for you. Would you let me know what is different in your application? What should be changed in the sample in order to replicate the problematic behavior?


    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. sharon
    sharon avatar
    27 posts
    Member since:
    Jul 2015

    Posted 08 Jul 2015 in reply to Viktor Tachev Link to this post

    Hi! Viktor,

       Thank you so much for trying to help.

    In my grid I have a dropdownlist column, when user doublclicking the row, I need to load the data for dropdownlist.

    I have looked for a lot of references on the web and finally find a solution that would load the dropdownlist, i am not sure if that's the part that make my BatchEditCommand event not working.

    I attached a file for some code I added, please see the attachment.

    The Rebind() in ItemCommand event will call NeedDataSource and then radGridStaff_ItemDataBound to load and populate data for dropdownlist.
    Then, when I click [savechanges] button, it will trigger BatchEditCommand event, but foreach (GridBatchEditingCommand gridBECmd in e.Commands) with e.Commands.count = 0

     

    Thanks!

    Sharon

  4. sharon
    sharon avatar
    27 posts
    Member since:
    Jul 2015

    Posted 08 Jul 2015 in reply to sharon Link to this post

    Well! It won't let me attach a text file, so I just paste it then.

    1. Client-side script
     <script type="text/javascript">
            function OnRowDblClick(sender, eventArgs) {
                var grid = $find("<%=radGridStaff.ClientID %>");
                var master = grid.get_masterTableView();
                editedRow = eventArgs.get_itemIndexHierarchical();
                master.fireCommand("DoubleClickEdit", editedRow);        }
     </script>

    2. RadGrid -- with <ClientSettings>
     <telerik:RadGrid ID="radGridStaff" runat="server" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" PageSize="5"
                        OnBatchEditCommand="radGridStaff_BatchEditCommand"
                        OnItemCommand="radGridStaff_ItemCommand"
                        OnUpdateCommand="radGridStaff_UpdateCommand"
                        OnItemDataBound="radGridStaff_ItemDataBound"
                        OnPreRender="radGridStaff_PreRender"
                        OnNeedDataSource="rdGridStaff_NeedDataSource"
                        OnPageSizeChanged="radGridStaff_PageSizeChanged">                     <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="BUSINESS_STUDIO_ID, ADD_YEAR, ADD_MONTH, STAFF_ID"
                            HorizontalAlign="NotSet" EditMode="Batch">
                           
                            <BatchEditingSettings EditType="Row" OpenEditingEvent="DblClick" />
                            <SortExpressions>
                                <telerik:GridSortExpression FieldName="STAFF_ID" SortOrder="Ascending" />
                            </SortExpressions>
                            <Columns>
                                <telerik:GridBoundColumn DataField="ADD_YEAR" HeaderText="Year" ItemStyle-Width="40px" ReadOnly="true"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ADD_MONTH" HeaderText="Month" ItemStyle-Width="40px" ReadOnly="true"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="STAFF_ID" HeaderText="STAFF ID" UniqueName="staffId" ReadOnly="true"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="StaffName" HeaderText="STAFF Name" ReadOnly="true"></telerik:GridBoundColumn>
                                           
                                <telerik:GridTemplateColumn HeaderText="Staff Position" UniqueName="StaffPost" DataField="POST_ID">
                                    <ItemTemplate>
                                        <%# (String.IsNullOrEmpty(Eval("POST_NAME").ToString())? "N/A": Eval("POST_NAME"))%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <telerik:RadDropDownList ID="radDDLStaffPost" Width="120px" runat="server"></telerik:RadDropDownList>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                               
                                <telerik:GridTemplateColumn HeaderText="Staff Goal" UniqueName="staffGoal" DataField="EXPECT_VALUE">
                                    <ItemTemplate>
                                        <asp:Label ID="lblGoal" Text ='<%# (Eval("EXPECT_VALUE") == DBNull.Value? "0": "$"+(Decimal.Parse(Eval("EXPECT_VALUE").ToString())))%>' runat="server"></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <telerik:RadTextBox ID="radTxtGoal" Width="120px" runat="server"></telerik:RadTextBox>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>                        </Columns>
                        </MasterTableView>
                        <ClientSettings AllowKeyboardNavigation="true">
                            <ClientEvents OnRowDblClick="OnRowDblClick" />
                        </ClientSettings>
                    </telerik:RadGrid>
    3. ItemCommend event for Double Click to load the dropdownlist
    protected void radGridStaff_ItemCommand(object sender, GridCommandEventArgs e)
        {
                if (e.CommandName == "DoubleClickEdit")
                {
                    GridDataItem radGridItem = radGridStaff.Items[e.CommandArgument.ToString()];
                    radGridItem.Edit = true;
                    radGridStaff.MasterTableView.EditMode = GridEditMode.Batch;
                    radGridStaff.Rebind();            }
        }


  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2252 posts

    Posted 10 Jul 2015 Link to this post

    Hi Sharon,

    I have examined the provided code and it seems that you are handling the OnRowDblClick client and firing custom command. Note that the fireCommand() method will cause postback. This, will prevent Batch Editing from working properly. Batch Editing relies on performing changes on the client.

    Please remove the OnRowDblClick event from RadGrid and see how the behavior changes. Also remove the ItemCommand server-side handler as it is not needed in this case.

    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. sharon
    sharon avatar
    27 posts
    Member since:
    Jul 2015

    Posted 15 Jul 2015 in reply to Viktor Tachev Link to this post

    Hi! Viktor,

       If I cannot use client-side OnRowDblClick function and cannot use radGridStaff_ItemCommand event, then what evnet I could use after the Double click action to the RadGrid?  There are no event being triggered.  That's why I finally found and used the client-side OnRowDblClick function to load and populate drop-down list.

    Thanks!

    Sharon

  7. sharon
    sharon avatar
    27 posts
    Member since:
    Jul 2015

    Posted 16 Jul 2015 in reply to sharon Link to this post

    I finally compromise and use front-end <asp:sqldatasource> for my drop-down to solve this whole issue.

    Thanks for pointing out cannot use fireCommand() method.

    Sharon

  8. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2252 posts

    Posted 17 Jul 2015 Link to this post

    Hi Sharon,

    I am glad that the issue was resolved. Let us know if you have additional queries.


    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top