Skip to content

How do I add a timestamp to a gridview

Enos

Asked Feb 26, 2015, 3:10 AM EST1 answer
Share
LinkedInX

How do I add a timestamp to a gridview that shows the last time a row was edited? I've been searching Google but haven't found anything helpful yet.

I tried to create a method which will update the time when you edit or add a column. but i dont know how to take it further like parsing it to each and every column.

my table columns
 
C#
 private DataTable GetDataTableFromDataGridview(DataGridView _grid)
    {
      {
            var _oDataTable = new DataTable();
            object[] cellValues = new object[_grid.Columns.Count];
             //clearTable();
            _oDataTable.Columns.Add("Name", typeof(string));
            _oDataTable.Columns.Add("Value", typeof(string));
            _oDataTable.Columns.Add("Font", typeof(string));
            _oDataTable.Columns.Add("DateStamp", typeof(string));
            _oDataTable.Columns.Add("Comment", typeof(string));
            foreach (DataGridViewRow row in _grid.Rows)
            {
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    cellValues[i] = row.Cells[i].Value;
                }
                _oDataTable.Rows.Add(cellValues.ToArray());
            }
            return _oDataTable;
        }

    }
 
 
C#
private DateTime _dateTime; string _DateTimeFormat = "yyyy/dd/MM HH:mm:ss"; public void UpdateTheCurrentTime() {         _dateTime = DateTime.Now;         _dateTime.ToString(_DateTimeFormat, CultureInfo.InvariantCulture); }
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Vithal Wadje
    0
    while updating row you need to update current datetime in database as well and while retrieving you need to fetch that column value as wel
    0