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

SavedOldValues collection and GridTemplateColumn

5 Answers 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 14 May 2008, 10:37 AM

Hi
Here's 2 different typed columns. Both have DataField specified

<telerik:GridBoundColumn DataField="ID" UniqueName="ID" Visible="False" > 
</telerik:GridBoundColumn> 
 
<telerik:GridTemplateColumn DataField="Name" HeaderText="Name" UniqueName="NameColumn">  
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "Name") %></ItemTemplate>   
<EditItemTemplate> 
<asp:TextBox ID="tbName" runat="server" SkinID="GeneralTextBox" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:TextBox>      
</EditItemTemplate>    
</telerik:GridTemplateColumn>   
 


However only "ID" exists in SavedOldValues collection (ItemCommand event):
Telerik.Web.UI.GridDataItem dataItem = e.Item as Telerik.Web.UI.GridDataItem;  
dataItem.SavedOldValues["ID"//this always have a value  
dataItem.SavedOldValues["Name"// this is not exists 


Why 'Name' is not contains in SavedOldValues collection when I use GridTemplateColumn?
I'm forced to do selection from dataset by ID to get original 'Name' value

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 May 2008, 11:49 AM

Hi Sergy,

You can retrieve the old values for the edited item through the SavedOldValues property of the GridEditableItem (which is IDictionary collection of key -> value pairs). The keys in this collection are the UniqueNames of the editable columns and the values are the cell content for the edited row before the edit operation. Try setting the proper UniqueName for the GridTemplateColumn.


dataItem.SavedOldValues["NameColumn"] 


Thanks
Princy.
0
Sebastian
Telerik team
answered on 14 May 2008, 11:55 AM
Hello guys,

Actually for template columns you need to store and retrieve the old values manually with coding. Review this topic from the online documentation which illustrates sample approach:

http://www.telerik.com/help/aspnet-ajax/grdretrieveoriginalvaluesforediteditem.html

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Lenny_shp
Top achievements
Rank 2
answered on 04 Dec 2008, 04:55 PM
What is the recommended approach for template column since we can not store a copy into SavedOldValues in ItemDataBound?
I am using InPlace Edit mode.     Do we create a hidden textbox to store it?
0
Sebastian
Telerik team
answered on 05 Dec 2008, 07:41 AM
Hi Lenny_shp,

Indeed if you are restricted from using the ItemDataBound event to store the old value from the textbox editor(s), consider including a hidden textbox inside the edit template of the template column and extract the value from it on update action.

Best,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Scott
Top achievements
Rank 1
answered on 30 Dec 2014, 11:16 PM
As Sebastian alluded to putting a hidden non-GridTemplateColumn with the template column will also automatically yield a value with the field name you're looking for in the SavedOldValues collection.  This way of course adds to the size of the page but avoids using a session variable.

<%--using hidden field in order to get field value to show up in saved old values collection--%><br><telerik:GridDateTimeColumn DataField="EffectiveDate" Visible="false"></telerik:GridDateTimeColumn><br><telerik:GridTemplateColumn DataField="EffectiveDate" HeaderText="Start Date" ItemStyle-VerticalAlign="Top" DataType="System.String"<br>UniqueName="EffectiveDate" SortExpression="EffectiveDate"><br>. . . <br></telerik:GridTemplateColumn>   
Tags
Grid
Asked by
Sergey
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sebastian
Telerik team
Lenny_shp
Top achievements
Rank 2
Scott
Top achievements
Rank 1
Share this question
or