Null Reference Exception while doing conditional formatting for radgrid
I am currently attempting to modify the way my radgrid displays data by
highlighting specific rows which has went over my "overdue" limit. here's
a snippet of the methods i am using...
ASPX
<telerik:GridBoundColumn DataField="TimeCreated" HeaderText="Posted On"
ReadOnly="true" UniqueName="TimeCreated"/>
C# Method 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# Method 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;
}
}
Both of these methods pproduces the same exact NullReferenceException
which is unfathomable to me, i hope someone could shed some light on this.
thanks
No comments:
Post a Comment