I think that's the right terminology...
Basically, I have a repeater control, and a Linq query that retrieves some items. Ordinarily I would databind straight to the query and use Eval to populate the template with the results.
However, it doesn't come through in quite the right format - for example, if EndDate is null (it's a DateTime?) then I want to substitute it with "Present". I am using only a couple of the properties in the query result objects.
I am wondering if there's a solution like:
[pseudo madeup code]
var query = getResults();
List<anonymous> anonList = new List();
foreach (var q in query)
{
string myEndDate = "";
if (q.EndDate.HasValue)
{ myEndDate = q.EndDate.ToString(); }
else
{ myEndDate = "Present"; }
anonList.items.add(new { name=q.name, enddate=myEndDate };
}
repeater.Datasource = anonList;
then
<div><%#Eval("enddate")%></div>
You have two options for declaring you result list:
ArrayList
, orEnumerable.Repeat
, ie. var anonList = Enumerable.Repeat(new { name="", enddate=""}, 0).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With