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

Updating RadGrid data as part of a larger transaction

6 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cory Benjamin
Top achievements
Rank 2
Cory Benjamin asked on 15 Sep 2008, 06:16 PM
Hi,

We are using the RadGrid on pages that also contain other fields that will be updated to the database.  For example, we might have a page with textboxes and other controls to add/edit a master record, and then use the RadGrid to add/edit associated detail records.

We want to update all of the detail records in the RadGrid at the same time that we update the master record, in a SQL transaction.

Presently, we have the RadGrid data-bound to a LLBLGen datasource (although for this discussion I believe we can just assume that we are using a normal SQLDataSource).  As we add/update/delete records in the grid, they are being updated immediately in the datasource.

Does anyone have any suggestions on how we can have all of the add/update/delete functionality in the grid take place internally (either client or server side), and then be mass-updated to the database when we are in our transaction to update the entire page?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 18 Sep 2008, 11:31 AM
Hello Cory Benjamin,

In the most general case, this requirement can be implemented by binding RadGrid to a simple data table or other container controls. When any data source update is made, the actual data container gets updated. And finally, on a button click or other event, the actual SQL source can be updated with all the changes in the data table.

Regards,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jlehew
Top achievements
Rank 1
answered on 15 Oct 2008, 08:14 PM
I'm trying to accomplish the same thing as Cory using the OnPerformWork event and the e.Uow.Commit method in LLBLGen v2.6 but am unable to get it to work.  It fires the OnPerformSelect event correctly but I can't get it to fire the OnPerformWork event in version 2008.2.1002.  I was able to get the GridView control to fire the event.

I'm using the "Adapter" generated code vs. the "Self Servicing" code.  Look in the LLBLGen help under "Data Binding with ASP.NET 2.0" for the method I used to tie everything together. 
   
using System;   
using System.Collections.Generic;   
using System.Linq;   
using System.Web;   
using System.Web.UI;   
using System.Web.UI.WebControls;   
using System.Data;   
using System.Configuration;   
using System.Web.Security;   
using System.Web.UI.WebControls.WebParts;    
using System.Web.UI.HtmlControls;   
 
using SD.LLBLGen.Pro.ORMSupportClasses;   
using ARMS.Data.DatabaseSpecific;   
 
public partial class _Default : System.Web.UI.Page   
{  
        protected void Page_Load(object sender, EventArgs e)   
        {  
        }  
 
 
        protected void DS_PerformGetDbCount(object sender, PerformGetDbCountEventArgs2 e)   
{  
    using(DataAccessAdapter adapter = new DataAccessAdapter())   
    {  
        e.DbCount = adapter.GetDbCount(e.ContainedCollection, e.Filter);  
    }  
}  
 
protected void DS_PerformSelect(object sender, PerformSelectEventArgs2 e)   
{  
    using(DataAccessAdapter adapter = new DataAccessAdapter())   
    {  
        adapter.FetchEntityCollection(e.ContainedCollection,   
        e.Filter,e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath,   
        e.PageNumber, e.PageSize);  
    }  
}  
 
protected void DS_PerformWork(object sender, PerformWorkEventArgs2 e)   
{  
    using(DataAccessAdapter adapter = new DataAccessAdapter())   
    {  
            e.Uow.Commit(adapter, true);   
     }  
}  
}  
 

 

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>   
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>   
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
 
<html xmlns="http://www.w3.org/1999/xhtml">   
<head runat="server">   
<title></title>   
</head>   
<body>   
<form id="form1" runat="server">   
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">   
</telerik:RadScriptManager>   
<div>   
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">   
</telerik:RadAjaxManager>   
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px">   
<img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'   
style="border: 0px;" />   
</telerik:RadAjaxLoadingPanel>   
</div>   
<llblgenpro:LLBLGenProDataSource2 ID="LLBLGenProDataSource1" runat="server" AdapterTypeName="ARMS.Data.DatabaseSpecific.DataAccessAdapter, ARMS.DataDBSpecific"   
DataContainerType="EntityCollection" LivePersistence="false" OnPerformSelect="DS_PerformSelect"   
OnPerformGetDbCount="DS_PerformGetDbCount" OnPerformWork="DS_PerformWork"   
EntityFactoryTypeName="ARMS.Data.FactoryClasses.LookupEntityFactory, ARMS.Data"   
CacheLocation="Session" SortingMode="ClientSide">   
<InsertParameters>   
<asp:Parameter Name="LookupID" Type="Int32" />   
<asp:Parameter Name="LookUpType" Type="String" />   
<asp:Parameter Name="LookupTitle" Type="String" />   
<asp:Parameter Name="LookupActiveYn" Type="String" />   
<asp:Parameter Name="LookupAbbr" Type="String" />   
<asp:Parameter Name="LookupShortTitle" Type="String" />   
</InsertParameters>   
<UpdateParameters>   
<asp:Parameter Name="LookupId" Type="Int32" />   
<asp:Parameter Name="LookUpType" Type="String" />   
<asp:Parameter Name="LookupTitle" Type="String" />   
<asp:Parameter Name="LookupActiveYn" Type="String" />   
<asp:Parameter Name="LookupAbbr" Type="String" />   
<asp:Parameter Name="LookupShortTitle" Type="String" />   
</UpdateParameters>   
 
</llblgenpro:LLBLGenProDataSource2>   
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" EnableLinqExpressions="false"   
PageSize="3" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" DataSourceID="LLBLGenProDataSource1"   
GridLines="None" DataMember="DefaultView">   
<MasterTableView DataSourceID="LLBLGenProDataSource1" AllowAutomaticDeletes="true"   
AllowAutomaticInserts="true" AllowAutomaticUpdates="true" DataKeyNames="LookupID"   
DataMember="DefaultView" AdditionalDataFieldNames="LookUpType, LookupTitle, LookupActiveYn, LookupAbbr, LookupShortTitle">   
<RowIndicatorColumn>   
<HeaderStyle Width="20px"></HeaderStyle>   
</RowIndicatorColumn>   
<ExpandCollapseColumn>   
<HeaderStyle Width="20px"></HeaderStyle>   
</ExpandCollapseColumn>   
</MasterTableView>   
<FilterMenu EnableTheming="True">   
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>   
</FilterMenu>   
</telerik:RadGrid>   
<br>   
<br>   
<br>   
<asp:GridView ID="GridView1" runat="server" DataSourceID="LLBLGenProDataSource1"   
DataKeyNames="LookupId" AllowPaging="True" PageSize="3" AutoGenerateColumns="False"   
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">   
<Columns>   
<asp:BoundField DataField="LookupId" HeaderText="LookupId" ReadOnly="True" SortExpression="LookupId" />   
<asp:BoundField DataField="LookUpType" HeaderText="LookUpType" SortExpression="LookUpType" />   
<asp:BoundField DataField="LookupTitle" HeaderText="LookupTitle" SortExpression="LookupTitle" />   
<asp:BoundField DataField="LookupActiveYn" HeaderText="LookupActiveYn" SortExpression="LookupActiveYn" />   
<asp:BoundField DataField="LookupAbbr" HeaderText="LookupAbbr" SortExpression="LookupAbbr" />   
<asp:BoundField DataField="LookupShortTitle" HeaderText="LookupShortTitle" SortExpression="LookupShortTitle" />   
</Columns>   
</asp:GridView>   
</form>   
</body>   
</html> 

Cory, if you would put up some sample code that would be great.  

Thanks,
John



 

0
Rosen
Telerik team
answered on 17 Oct 2008, 03:21 PM
Hi,

Unfortunately I was unable to reproduce the behavior you are describing. I have attached a simple project with which I'm testing. Please take a look, maybe I'm missing something obvious.

Sincerely yours,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jlehew
Top achievements
Rank 1
answered on 12 Dec 2008, 07:26 AM
I was able to get your sample app to run and after reviewing it, I should have clarified this in my previous post... 

Clicking Update calls the PerformWork method correctly, but if AutoGenerateDeleteColumn="true" is added to this sample app, clicking the Delete shortcut it does not call PerformWork.  The asp:GridView does call it when Deleting is clicked but the RadGrid doesn't.

Running version 2008.3.1105.

Thanks,
John
0
Rosen
Telerik team
answered on 15 Dec 2008, 07:44 AM
Hello,

Can you please check if you have AllowAutomaticDeletes option set to true? More information about automatic operation can be found in our help documentation here.

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jlehew
Top achievements
Rank 1
answered on 19 Dec 2008, 05:04 PM
That was it.  Once I added that property it worked. 

Thanks,
John
Tags
Grid
Asked by
Cory Benjamin
Top achievements
Rank 2
Answers by
Veli
Telerik team
jlehew
Top achievements
Rank 1
Rosen
Telerik team
jlehew
Top achievements
Rank 1
Share this question
or