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;
}
}
Source: stackoverflow.com
Related Articles
- C# LINQ: How to check object value of a listbox item and set color accordingly
- linq remove item from object array where property equals value
- How do I check return a value of this object using Linq
- LINQ to check each property of a list object to see if it's value is equal to a string
- Check Nullable for object insde LinQ to Sql code
- nullable object must have a value error in linq to sql in vb.net code
- How to use LINQ to select object with minimum or maximum property value
- How can I get LINQ to return the object which has the max value for a given property?
- Linq code to select one item
- LINQ FirstOrDefault check for default value
- Check that all items of IEnumerable<T?> has the same value using LINQ
- LINQ - Returning value of a property of an object that is not null
- Simple check to see if at least one object in a set has a property value of TRUE
- Default value for linq select item if query didn't return anything
- Check if a value is in a collection with LINQ
- LINQ SQL query check if a object field is not null
- Check if results from LINQ query contains a value
- check whether the list contains item greater than a value in C#
- Best way to check if value exists for a key in ILookup<string, string> using linq
- How can I get LINQ to return the index of the object which has the max value in a collection?
- LINQ Source Code Available
- Check if object is Null in Linq Query
- Linq with where clause in many-to-many EF Code First object
- Linq query, how to check for a null value and use the value 0 in place of a null?
- Linq check for null and replace null value in orderby
- Apply a linq expression of an object to a list of items where that object is a propery of an item (Wrapper)
- How to check DBNull value in Linq query results
- MVC Controller: Using LINQ to check for duplicate value already existing in table before Save?
- Check null value in a list using linq
- LINQ to check boolean value
- Is there any equivalent method to `Find` with composite key
- C# Linq, find lowest value in List<int> between two numbers
- Can a linq to objects SelectMany selector result in nothing added to the collection?
- Replace Duplicates with unique string in Dictionary<string,list<object>>
- Finding Duplicates based On A Property In Object
- LINQ Where Clause always returns an empty list
- LINQ update method doesn't update the Db
- Given a Member Access lambda expression, convert it to a specific string representation with full access path
- Missing characters after string concatenate
- TargetParameterCountException when mocking function to return its input
- How can I order in Linq Select Distinct if ordered by an Included entity?
- Wrting a SQL query in LINQ
- LINQ Min() and Max() optimisation
- where on LINQ with DataTable
- How to make nested list operations?
- Filter IENumerable of Interface with property of class outside of interface
- LINQ - grouping and aggregation
- How do I construct a nested, strongly typed object from a flat ("non-normalized") array?
- how to print the innertext of an element based on attribute search of a particular node using LINQ?
- How can I include a predicate along with Included properties?