I have a list of data in a data table, I also have a button that when clicked Will Show the Rows that have been completed in the last week.
However, I cant get the table to update after the modifications for some reason
I get the date of 7 days ago, and for every row that has a completed date greater than it in the source DataTable, I delete that row. That should leave me with only rows completed in the last week, but for some reason every row remains after my method is done. Can anyone spot a problem here?
Thanks in advance for any help!
protected void btnShowLastWeek_OnClick(Object sender, EventArgs e)
{
DateTime current = DateTime.Today;
DateTime lastWeek = current.AddDays(-7);
DataTable temp = compDV.Table;
for(int i = 0; i < temp.Rows.Count; i ++)
{
DateTime completed = (DateTime)temp.Rows[i]["DateCompleted"];
if (completed.CompareTo(lastWeek.Date) <= 0)
{
temp.Rows.RemoveAt(i);
}
}
dgCompletedRequests.DataSource = temp;
dgCompletedRequests.DataBind();
}