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

RadGrid Audit Trail

2 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 11 Mar 2014, 06:57 PM
Hi All,

I have a RadGrid with Sqldatasource.  Is there anyway to implement some sort of auditing mechanism?  Perhaps a shadow copy of the modified table that contains a list of the changes and all legacy instances of the rows?

Thanks,
Mark

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Mar 2014, 01:47 PM
Hello Mark,

Since you have not specify the exact requirement that you have and what you want to accomplish, I could only assume that you want to log the changes performed in the grid by each user. 

Please note that RadGrid does not have such built-in functionality, but you can handle the server-side OnUpdateCommand, OnInsertCommand and OnDeleteCommand events, get reference to the edited item through the event arguments (e.Item) and use the values in that item for your log. 

Following is a simple example of the above:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnUpdateCommand="RadGrid1_UpdateCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));
 
    table.Rows.Add(1, "SomeName");
    table.Rows.Add(2, "SomeName");
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    if (e.Item is GridEditFormItem)
    {
        GridEditFormItem item = e.Item as GridEditFormItem;
        string id = (item["ID"].Controls[0] as RadNumericTextBox).Value.ToString();
        string newNameValue = (item["Name"].Controls[0] as TextBox).Text;
        // your custom logic
    }
}

Hope that helps.


Regards,
Konstantin Dikov
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
Mark
Top achievements
Rank 1
answered on 14 Mar 2014, 02:38 PM
Konstantin,

Thanks for the reply!  I actually just began implementing functionality similar to that where I have my own custom sql commands that insert data from the table.  Sort of a shadow copy where I grab the dataitem text and insert it into the audit table.

-Mark
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or