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

Saving old values

1 Answer 91 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 29 Dec 2014, 08:50 PM
What is the recommended method of accessing a record's old values when it is updated via a data form control?  I've tried accessing 'e.Item.SavedOldValues' from the 'ItemUpdated' event, but the values are null.

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 01 Jan 2015, 12:45 PM
Hello Rich,

I have tested the described scenario with our latest version (2014.3 1209) and all the values are available in the SavedOldValues collection. Following is the example that I have tested:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemUpdated="RadGrid1_ItemUpdated"
    AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True"
    AllowAutomaticDeletes="true" AllowSorting="true">
    <PagerStyle Mode="NextPrevAndNumeric" />
    <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
        DataKeyNames="CustomerID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID"
                UniqueName="CustomerID" Visible="false" MaxLength="5">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName"
                UniqueName="ContactName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName"
                UniqueName="CompanyName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle"
                UniqueName="ContactTitle">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" SortExpression="Phone"
                UniqueName="Phone">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" />
        </Columns>
        <EditFormSettings>
            <EditColumn ButtonType="ImageButton" />
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
 
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:NorthwindConnectionString %>'
    DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID"
    InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax], [Bool]) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax, @Bool)"
    SelectCommand="SELECT * FROM [Customers]"
    UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, [Address] = @Address, [City] = @City, [Region] = @Region, [PostalCode] = @PostalCode, [Country] = @Country, [Phone] = @Phone, [Fax] = @Fax, [Bool] = @Bool WHERE [CustomerID] = @CustomerID">
    <DeleteParameters>
        <asp:Parameter Name="CustomerID" Type="String"></asp:Parameter>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="CustomerID" Type="String"></asp:Parameter>
        <asp:Parameter Name="CompanyName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ContactName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ContactTitle" Type="String"></asp:Parameter>
        <asp:Parameter Name="Address" Type="String"></asp:Parameter>
        <asp:Parameter Name="City" Type="String"></asp:Parameter>
        <asp:Parameter Name="Region" Type="String"></asp:Parameter>
        <asp:Parameter Name="PostalCode" Type="String"></asp:Parameter>
        <asp:Parameter Name="Country" Type="String"></asp:Parameter>
        <asp:Parameter Name="Phone" Type="String"></asp:Parameter>
        <asp:Parameter Name="Fax" Type="String"></asp:Parameter>
        <asp:Parameter Name="Bool" Type="Boolean"></asp:Parameter>
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="CompanyName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ContactName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ContactTitle" Type="String"></asp:Parameter>
        <asp:Parameter Name="Address" Type="String"></asp:Parameter>
        <asp:Parameter Name="City" Type="String"></asp:Parameter>
        <asp:Parameter Name="Region" Type="String"></asp:Parameter>
        <asp:Parameter Name="PostalCode" Type="String"></asp:Parameter>
        <asp:Parameter Name="Country" Type="String"></asp:Parameter>
        <asp:Parameter Name="Phone" Type="String"></asp:Parameter>
        <asp:Parameter Name="Fax" Type="String"></asp:Parameter>
        <asp:Parameter Name="Bool" Type="Boolean"></asp:Parameter>
        <asp:Parameter Name="CustomerID" Type="String"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>

And the code-behind:
protected void RadGrid1_ItemUpdated(object sender, GridUpdatedEventArgs e)
{
    Hashtable oldValues = e.Item.SavedOldValues as Hashtable;     
}

Please examine the above and see what differs in your implementation.


Best Regards,
Konstantin Dikov
Telerik
Tags
DataForm
Asked by
Rich
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or