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

rad grid edit functionality

5 Answers 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sudhakar
Top achievements
Rank 1
Sudhakar asked on 07 Oct 2014, 10:19 AM
Hi Team,

i have a grid which is having some rows in it.I need to implement editing functionality for each row in the grid.
i am using the editmode=batch properity for this to achieve.
once edit has completed i need to update the changes  in the database when i click on the save changes button.
and also cancel changes by clicking on the cancel button.
i am also need to implement add a new record and update the new record in to the database.

ASPX File:
<telerik:RadGrid ID="RadGrid1" OnItemDataBound="RadGrid1_OnItemDataBound"
runat="server" AutoGenerateColumns="false" CssClass="TransferGridPanel" Height="375px"
Width="500px" OnNeedDataSource="RadGrid1_NeedDataSource" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" onItemUpdated="RadGrid1_ItemUpdated"
OnBatchEditCommand="RadGrid1_BatchEditCommand" OnItemInserted="RadGrid1_ItemInserted"
 OnItemCommand="RadGrid1_ItemCommand" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
   <MasterTableView ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top" EditMode="Batch">
    <BatchEditingSettings EditType="Cell" />
<Columns>
          <telerik:GridBoundColumn UniqueName="Id" DataField="Loading_ID">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn UniqueName="TerminalId" DataField="Plant_ID">
          </telerik:GridBoundColumn>
          <telerik:GridBoundColumn UniqueName="TerminalName" DataField="TerminalName">
          </telerik:GridBoundColumn>
         <telerik:GridBoundColumn UniqueName="StartTime" dataField="LoadingStartTime">
         </telerik:GridBoundColumn>
         <telerik:GridBoundColumn UniqueName="EndTime" DataField="LoadingEndTime">
         </telerik:GridBoundColumn>
</Columns>

How to achieve the above operations  in codebehind file.
‚Äč

5 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 10 Oct 2014, 09:22 AM
Hi Sudhakar,

I have prepared a sample project that illustrates how you could handle updating and inserting items manually. It is attached to this post.

Also, if you would like additional information on Batch Editing and how it works you would find the following resources interesting:

 
Regards,

Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Sudhakar
Top achievements
Rank 1
answered on 15 Oct 2014, 01:00 PM
Hi Viktor,

Thanks for your reply.

I have few more things to implement on the same requirement.
1) How to cancel the edits when I click on the cancel changes button.
2) I need to display the alert box(see the attachment) when I click on the add new record button as well as while editing the record in side the grid.


0
Viktor Tachev
Telerik team
answered on 20 Oct 2014, 10:57 AM
Hello Sudhakar,

The first requirement you describe is available for RadGrid out of the box. When you click on Cancel Changes the grid is rebound and all unsaved changes are discarded.

Regarding your second requirement. You can use some of the client-side events available when Batch editing is enabled. For example OnBatchEditClosing. Using the handler for this event you can show a confirm dialog and cancel the changes made to the cell.

function batchEditClosing(sender, args) {
     
    if (!confirm("Are you sure?") ) {
        args.set_cancel(true);
    }
     
}



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Sudhakar
Top achievements
Rank 1
answered on 22 Oct 2014, 11:09 AM
Hi Viktor,

When I click on the cancel button the page is showing blank screen.
I am using "OnCancelCommand" event in the grid.

<telerik:RadGrid ID="LoadingRadGrid" OnItemDataBound="LoadingRadGridFormat_OnItemDataBound"
                            runat="server" AutoGenerateColumns="false" CssClass="TransferGridPanel" Height="375px"
                            Width="500px" OnNeedDataSource="LoadingRadGrid_NeedDataSource"
                             OnUpdateCommand="LoadingRadGrid_UpdateCommand" OnBatchEditCommand="LoadingRadGrid_BatchEditCommand" OnInsertCommand="LoadingRadGrid_InsertCommand"
                             OnItemCommand="LoadingRadGrid_ItemCommand" OnSelectedIndexChanged="LoadingRadGrid_SelectedIndexChanged" OnCancelCommand="LoadingRadGrid_CancelCommand">

In code behind file I am writing the below code.
protected void LoadingRadGrid_CancelCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.CancelCommandName)
{
LoadingRadGrid.MasterTableView.IsItemInserted = false;
LoadingRadGrid.Rebind();
}
}

Thanks in advance.

0
Viktor Tachev
Telerik team
answered on 27 Oct 2014, 08:20 AM
Hello Sudhakar,

There is no need to set the IsItemInserted property and rebind the RadGrid manually. When the Cancel Button is clicked RadGrid calls Rebind() automatically. Thus, discarding any unsaved changes. Try to replace the code in CancelCommand handler and see how the behavior changes.

With this said, is the approach suggested in my previous post working for you?

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Sudhakar
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Sudhakar
Top achievements
Rank 1
Share this question
or