SavedOldValues collection and GridTemplateColumn

6 posts, 0 answers
  1. Sergey
    Sergey avatar
    17 posts
    Member since:
    Jan 2008

    Posted 14 May 2008 Link to this post

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

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

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 May 2008 Link to this post

    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.


  3. DevCraft R3 2016 release webinar banner
  4. Sebastian
    Sebastian avatar
    9934 posts

    Posted 14 May 2008 Link to this post

    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:

    Best regards,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 04 Dec 2008 Link to this post

    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?
  6. Sebastian
    Sebastian avatar
    9934 posts

    Posted 05 Dec 2008 Link to this post

    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.

    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Scott
    Scott avatar
    2 posts
    Member since:
    May 2014

    Posted 30 Dec 2014 Link to this post

    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>   
Back to Top
DevCraft R3 2016 release webinar banner