BatchEdit CommandItemTemplate

5 posts, 1 answers
  1. Virgil Rodriguez
    Virgil Rodriguez avatar
    70 posts
    Member since:
    Oct 2008

    Posted 06 Oct Link to this post

    Hi Telerik,

    Can you please create a working sample project in VB with a RadGrid that has the following properties/specs:

     

    1. Multiple columns (FIRST_NAME, LAST_NAME, AGE)
    2. Allow sorting and filtering on all three columns
    3. EditMode="InPlace", EditType="Cell", OpenEditingEvent="DblClick"
    4. CommandItemTemplate with "Edit","Save Changes" and "Cancel Changes" link buttons.
    5. The "Save Changes" and "Cancel Changes" link buttons are not displayed at first.
    6. And because initially EditMode="InPlace", NO edits should be allowed when any row or cell is double-clicked.
    7. When the "Edit" link button is clicked:
    • the "Edit" link button is hidden and the "Save Changes" and "Cancel Changes" appear
    • EditMode is changed to "Batch"
    • When double-clicking any cell of any row, ONLY the AGE cell of the row that was clicked will be editable.
    • When edting a cell (AGE), pressing the ENTER key should move the cursor to the same cell (AGE) but on the next row.
    • When the "Save Changes" link button is clicked, it should save whatever changes were made and also do some stuff on the server-side.
    • When the "Cancel Changes" link button is clicked, it should discard whatever changes were made and also do some stuff on the server-side.
    • The "Save Changes" and "Cancel Changes" link buttons should disappear and the "Edit" link button should re-appear.

    I've been pulling my hair over this for the past 3 days and I can't seem to make it work. If my requirements are not possible, can you please suggest an alternative - my MAIN concern is that the Grid should only allow editing when the "Save Changes" and "Cancel Changes" link buttons appear after the "Edit" link button is clicked.

    As always, many thanks in advance.

     

    Virgil Rodriguez

  2. Virgil Rodriguez
    Virgil Rodriguez avatar
    70 posts
    Member since:
    Oct 2008

    Posted 06 Oct in reply to Virgil Rodriguez Link to this post

    I forgot to mention, please pre-populate the data source. You will notice that I did not include an "Add New Record" link button. My requirement does not need that functionality.

    Thanks again.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Virgil Rodriguez
    Virgil Rodriguez avatar
    70 posts
    Member since:
    Oct 2008

    Posted 07 Oct in reply to Virgil Rodriguez Link to this post

    Sorry, in addition, the RadGrid mentioned above is within an ASCX file which is embedded within an ASPX file that has the following controls of its own:

    1. Department Textbox
    2. Manager TextBox
    3. Close Button
    • When the "Edit" link button in the RadGrid in the ASCX file is clicked, the Department Textbox, the Manager Textbox and the Close button in the parent ASPX file should be DISABLED.
    • When the "Save Changes" or "Cancel Changes" link button in the RadGrid in the ASCX file is clicked, the Department Textbox, the Manager Textbox and the Close button in the parent ASPX file should be re-ENABLED.

    This is as basic as it is but I still could not make it work. Your help is greatly appreciated.

    Thank you once again.

     

  5. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 11 Oct Link to this post

    Hello Virgil,

    For enabling the Batch editing through a button from the CommandItem you should define that item in the CommandItemTemplate and handle the OnItemCommand event of the grid to set the EditMode of the MasterTableView to "Batch" and rebind the grid. For your convenience, following is a simple example with such implementation, which also removes the CommandItemTemplate once the editing is enabled, because otherwise you will have to define custom "Save changes" and "Cancel changes" buttons that will use the client-side API of the Batch editing manager:
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
        <MasterTableView CommandItemDisplay="Top">
            <CommandItemTemplate>
                <telerik:RadButton runat="server" ID="EnableEditButton" Text="Edit" CommandName="EnableEdit"></telerik:RadButton>
            </CommandItemTemplate>
        </MasterTableView>
    </telerik:RadGrid>

    And the code-behind:
    Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
        Dim table As New DataTable()
        table.Columns.Add("ID", GetType(Integer))
        table.Columns.Add("FirstName", GetType(String))
        table.Columns.Add("LastName", GetType(String))
        table.Columns.Add("Age", GetType(Integer))
        table.Columns.Add("Date", GetType(DateTime))
        table.Columns.Add("BoolValue", GetType([Boolean]))
        table.Rows.Add(1, "FirstName1", "LastName1", 20, DateTime.Now.AddDays(i), i Mod 2 = 0)
     
        TryCast(sender, RadGrid).DataSource = table
    End Sub
     
    Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
        If e.CommandName = "EnableEdit" Then
            TryCast(sender, RadGrid).MasterTableView.EditMode = GridEditMode.Batch
            TryCast(sender, RadGrid).MasterTableView.CommandItemTemplate = Nothing
            TryCast(sender, RadGrid).MasterTableView.CommandItemSettings.ShowAddNewRecordButton = False
            TryCast(sender, RadGrid).Rebind()
        End If
    End Sub

    You can use the OnItemCommand event to disable the close button in the parent page and enable it when you perform the saving. 

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Virgil Rodriguez
    Virgil Rodriguez avatar
    70 posts
    Member since:
    Oct 2008

    Posted 11 Oct in reply to Konstantin Dikov Link to this post

    Thank you very much Konstantin!

    Everything now works as desired.

    Excellent support as always!

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017