我目前正在尝试通过突出显示超出我的“过期”限制的特定行来修改我的 radgrid 显示数据的方式。这是我正在使用的方法的片段...
ASPX
<telerik:GridBoundColumn DataField="TimeCreated" HeaderText="Posted On" ReadOnly="true" UniqueName="TimeCreated"/>
C# 方法 1
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem dataItem = e.Item as GridDataItem;
string time = dataItem["TimeCreated"].Text;
DateTime timePosted = DateTime.Parse(time);
TimeSpan allowance = new TimeSpan(0, 25, 0);
DateTime overdue = timePosted.Add(allowance);
if (DateTime.Now > overdue)
{
dataItem.ForeColor = System.Drawing.Color.LightPink;
dataItem.Font.Bold = true;
}
}
C# 方法 2
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem dataItem = e.Item as GridDataItem;
TimeSpan allowance = new TimeSpan(0, 25, 0);
if (DateTime.Compare(Convert.ToDateTime(dataItem["TimeCreated"].Text).Add(allowance), DateTime.Now) > 0)
{
dataItem.ForeColor = System.Drawing.Color.LightPink;
dataItem.Font.Bold = true;
}
}
C# 方法 3
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem dataItem = e.Item as GridDataItem;
TimeSpan allowance = new TimeSpan(0, 25, 0);
if (DateTime.Parse(dataItem["TimeCreated"].Text).Add(allowance) > DateTime.Now )
{
dataItem.ForeColor = System.Drawing.Color.LightPink;
dataItem.Font.Bold = true;
}
}
所有这些方法都会产生完全相同的 NullReferenceException,这对我来说是深不可测的,我希望有人能对此有所了解。谢谢