score:1

try this

var allHolds =
            from a in db.Record_HoldDatas
            join f in db.LUT_Flavors on a.Flavor equals f.ID
            into flavorNames
            where a.HoldStatus == "Open"
            from grouped in flavorNames
            select new { a.HoldID, a.DateOpened, grouped.flavor, a.NonConformingItem, 
            Caption = a.HoldID + " - " + a.Package + " " + grouped.flavor, 
            BackColor = (DateTime.Now - a.DateOpened).TotalHours >= 48 ? "Red" : "Blue" };

and

        lbxHoldCaption.DataSource = allHolds;
        lbxHoldCaption.DisplayMember = "Caption";
        lbxHoldCaption.DataBindings.Add("BackColor", allHolds,"BackColor");

score:1

foreach (ListItem xx in ListBox1.Items)
    {

        if (Convert.ToInt32(xx.Value) == 3)
        {

            xx.Attributes["style"] = "background-color:red;";

        }
     }

dont forget about those properties of ListBox : DataTextField="Caption" DataValueField="DateOpened"

score:1

Simple, use the var keyword, that way you don't need to specify the type explicitly.

foreach(var obj in allHolds)
{
     then = obj.DateOpened;
     span = now - then;

     if(span.TotalHours >= 48)
     {
          obj.BackColor = Color.Red;
     }
}

Related Articles