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

[Solved] Update - item contains old values

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ingo Dignas
Top achievements
Rank 1
Ingo Dignas asked on 09 Jun 2009, 02:16 PM
I'm just testing the controls and have a problem regarding the update.

Here is my Grid:

<

 

telerik:RadGrid ID="RadGrid1" runat="server"

 

 

oncolumncreated="RadGrid1_ColumnCreated" AutoGenerateColumns="False"

 

onupdatecommand="RadGrid1_UpdateCommand" AutoGenerateEditColumn="True"

 

GridLines="None" onitemdatabound="RadGrid1_ItemDataBound1" AllowAutomaticUpdates="true" >

 

 

 

<MasterTableView GridLines="None" Width="100%" EditMode="PopUp" DataSourceID="OpenAccessDataSource1" DataKeyNames="CustomerID" CommandItemDisplay="Top" >

 

<Columns>

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />

 

 

 

<telerik:GridBoundColumn  DataField="CustomerID"

 

DataType="System.Int32"

 

HeaderText="CustomerID"

 

SortExpression="CustomerID"

 

UniqueName="CustomerID" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Name1"

 

HeaderText="Name1"

 

SortExpression="Name1"

 

UniqueName="Name1" />

 

<telerik:GridBoundColumn

 

DataField="Name2"

 

HeaderText="Name2"

 

SortExpression="Name2"

 

UniqueName="Name2" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Street1"

 

HeaderText="Street1"

 

SortExpression="Street1"

 

UniqueName="Street1" />

 

<telerik:GridBoundColumn

 

DataField="Street2"

 

HeaderText="Street2"

 

SortExpression="Street2"

 

UniqueName="Street2" />

 

 

 

<telerik:GridBoundColumn

 

DataField="City"

 

HeaderText="City"

 

SortExpression="City"

 

UniqueName="City" />

 

<telerik:GridBoundColumn

 

DataField="Zip"

 

HeaderText="Zip"

 

SortExpression="Zip"

 

UniqueName="Zip" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Phone"

 

HeaderText="Phone"

 

SortExpression="Phone"

 

UniqueName="Phone" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Fax"

 

HeaderText="Fax"

 

 

SortExpression="Fax"

 

UniqueName="Fax" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Mobile"

 

HeaderText="Mobile"

 

SortExpression="Mobile"

 

UniqueName="Mobile" />

 

 

 

<telerik:GridBoundColumn

 

DataField="Website"

 

HeaderText="Website"

 

SortExpression="Website"

 

UniqueName="Website" />

 

</Columns>

 

 

 

<EditFormSettings ColumnNumber="2" CaptionDataField="CustomerID">

 

<FormTableItemStyle Wrap="False"></FormTableItemStyle>

 

<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>

 

<FormMainTableStyle CellSpacing="0" CellPadding="3" Width="100%" />

 

<FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"

 

Height="110px" Width="100%" />

 

 

 

 

 

<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>

 

<FormStyle Width="100%" BackColor="#EEF2EA"></FormStyle>

 

<EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">

 

</EditColumn>

 

 

<FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>

 

</EditFormSettings>

 

<ExpandCollapseColumn Visible="False">

 

<HeaderStyle Width="19px"></HeaderStyle>

 

</ExpandCollapseColumn>

 

<RowIndicatorColumn Visible="False">

 

<HeaderStyle Width="20px" />

 

</RowIndicatorColumn>

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

And here is my update function (just a test). This won't work, because the values are still the same. After executing the update a get a javascript error (concurrent updates). 

 

protected

 

void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

 

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();

 

var customer = from c in scope.Extent<Customer>()

 

where c.CustomerID == 4 select c;

 

scope.Transaction.Begin();

 

 

foreach (Customer cust in customer)

 

{

cust.Name1 = (editedItem[

 

"Name1"].Controls[0] as TextBox).Text;

 

cust.Name2 = (editedItem[

 

"Name2"].Controls[0] as TextBox).Text;

 

cust.Street1 = (editedItem[

 

"Street1"].Controls[0] as TextBox).Text;

 

cust.Street2 = (editedItem[

 

"Street2"].Controls[0] as TextBox).Text;

 

cust.City = (editedItem[

 

"City"].Controls[0] as TextBox).Text;

 

cust.Zip = (editedItem[

 

"Zip"].Controls[0] as TextBox).Text;

 

cust.Phone = (editedItem[

 

"Phone"].Controls[0] as TextBox).Text;

 

cust.Fax = (editedItem[

 

"Fax"].Controls[0] as TextBox).Text;

 

cust.Mobile = (editedItem[

 

"Mobile"].Controls[0] as TextBox).Text;

 

cust.Website = (editedItem[

 

"Website"].Controls[0] as TextBox).Text;

 

}

scope.Transaction.Commit();

 

 

 

}

 

 

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 12 Jun 2009, 01:21 PM

Hello Joerg,

If you would like to perform manual updates intercepting the OnUpdateCommand event of the grid, you will need to set the AllowAutomaticUpdates property of the control to false (it should be set to true only when performing automatic editing operations with data source controls).

Additionally, how to extract the new values from the grid column editors you can see from the examples below:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx

Kind regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Ingo Dignas
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or