It is not going to help with the issue.
But that if condition can be removed. Just a suggestion.
for (i=0; i < DataList1.Items.Count; i++)
{
((System.Web.UI.WebControls.Image)(DataList1.Items[i].FindControl("Image40"))).Visible = (((DataList)(DataList1.Items[i].FindControl("DataList3"))).Items.Count <= 0);
}