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

Viewing all past entries in RadGrid

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sadie
Top achievements
Rank 1
Sadie asked on 12 Dec 2013, 10:37 PM
Hello,

I have a Grid now that is updated once a day with changes on various status' from my users. My question is, does anyone have any ideas on how to save those previous entries to an archive that the user can go into and view previous entries?

The goal would be to have this archive and then after a certain point those archived entries would be deleted to avoid taking up too much database room unnecessarily.

Right now here is how I am saving my grid to my database, I just wasn't sure on how to expand on this to get that additional functionality.

private void SaveDataInDataTable()
{
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        if (item.IsInEditMode)
        {
            int rowID = (int)item.GetDataKeyValue("ID");
            for (int i = 2; i < RadGrid1.MasterTableView.RenderColumns.Length; i++)
            {
                GridColumn column = RadGrid1.MasterTableView.RenderColumns[i];
                DataRow myDataRow = GridSource.Select("ID = " + rowID)[0];
                object value = GetColumnValue(column, item);
             
                if (column.DataType == typeof(int))
                {
                    if (value == string.Empty || value == null)
                    {
                        myDataRow[column.UniqueName] = DBNull.Value;
                    }
                    else
                    {
                        int parsedValue;
                        if (int.TryParse(value.ToString(), out parsedValue))
                        {  
                            myDataRow[column.UniqueName] = parsedValue;
                        }
                        else
                        {
                            myDataRow[column.UniqueName] = myDataRow[column.UniqueName];
                            RadAjaxManager1.Alert(string.Format("Value {0} is not valid for column {1}, row {2}. The old value was used!", value, column.UniqueName, item.ItemIndex+1));
                        }
                    }
                }
                else if (value == null)
                {
                    myDataRow[column.UniqueName] = DBNull.Value;
                }
                else if ((GridSource.Columns[column.UniqueName].MaxLength < value.ToString().Length) && GridSource.Columns[column.UniqueName].MaxLength != -1)
                {
                    myDataRow[column.UniqueName] = value.ToString().Substring(0, 5);
                }
                else
                {
                    myDataRow[column.UniqueName] = GetColumnValue(column, item);
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 17 Dec 2013, 09:34 AM
Hi Sadie,

To achieve the desired functionality you can try adding a new column into the database which can hold the date of the change. When the user updated the record into the grid you do not update the current one, but instead insert new record with the current date of the change. In that way every record will have a history and you can load into the grid all records for a date. For example the date can be selected form a combo box. Also more information about tracking changes into the database you can find into the following articles:

http://msdn.microsoft.com/en-us/library/bb933994.aspx
http://technet.microsoft.com/bg-bg/magazine/2008.11.sql(en-us).aspx
http://www.codeproject.com/Articles/537649/SQL-Server-Change-Tracking-CT
http://www.codeproject.com/Articles/338183/SQL-Server-Change-Tracking-on-Table-Without-Trigge

I hope this helps.

Regards,
Radoslav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Sadie
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or