I am facing a strange behaviour for an .aspx page.
I have DataList called MyDataList
. I need to conditionally highlight the rows of the DataList, depending on an arbitrary value in the data, such as if a Date
field is less then SomeDate
.
I am using an UpdatePanel, ScriptManager and a timer (all AJAX) to refresh MyDataList.
protected void Timer1_Tick(object sender, EventArgs e)
{
MyDataList.DataBind();
}
protected void MyDataList_ItemCreated(object sender, DataListItemEventArgs e)
{
}
The Problem:
If I add an empty event handler for the ItemCreated
event (EG, MyDataList_ItemCreated
), it works fine (as shown above).
If I provide code to highlight the value in the ItemCreated
event handler (as shown below), the Timer stops ticking, and the event Timer1_Tick
does not fire any more.
protected void DataListBgArticles_ItemCreated(object sender,
DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Product product = (Product)e.Item.DataItem;
if (product.SaleDate > DateTime.Now.AddDays(-2))
{
e.Item.BackColor = Color.Pink;
}
}
}
How can I fix this so that the Timer continues to update?