这对我来说没有意义:如果我运行这段代码:
protected void viewStoryTime_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var obj = ((DataRowView)e.Row.DataItem)["ActivityDate"];
if (DateTime.Parse(obj.ToString()) < DateTime.Now.StartOfWeek(DayOfWeek.Monday))
{
System.Diagnostics.Debug.WriteLine(e.Row.RowIndex);
}
}
}
我的输出是:
4
现在,如果我尝试使用它来清除单元格:
protected void viewStoryTime_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var obj = ((DataRowView)e.Row.DataItem)["ActivityDate"];
if (DateTime.Parse(obj.ToString()) < DateTime.Now.StartOfWeek(DayOfWeek.Monday))
{
viewStoryTime.Rows[e.Row.RowIndex].Cells[3].Controls.Clear();
}
}
}
我得到:
在 mscorlib.dll 中发生了“System.ArgumentOutOfRangeException”类型的第一次机会异常
此外,如果我手动输入 4,则会出现此异常:
viewStoryTime.Rows[e.Row.RowIndex].Cells[3].Controls.Clear();
但是,如果我输入 3,它会直接从列中删除它应该在该列之前的控件:
为什么我会收到此异常,我该怎么办?