Last post Jun 09, 2011 06:02 AM by Hugo1024
May 12, 2008 04:19 PM|avalutions|LINK
I need to populate a dropdown with a distinct list of years available from a datetime field. I don't even know if its feasable (or reasonable) but was just curious if anyone knew of a way to do something like this?
May 13, 2008 04:28 AM|lionscub|LINK
Check out this article: http://www.ddj.com/205100230
May 15, 2008 04:31 AM|Wencui Qian - MSFT|LINK
As far as I know, you couldn't use Distinct key words in LinqDataSource. I suggest you could use ObjectDataSource to achieve it. Anyone who has better solutions could share with us. Hope this helps you!
You can write a BLL method to get the list of dateTime field with Distinct key words.
var res = (from u in ctx.Users select u.dateTime).Distinct();
Then in UI you can bind this method to the Select method of ObjectDataSource control.
Jun 09, 2011 06:02 AM|Hugo1024|LINK
You could use the GroupBy attribute to achieve a Distinct.
It works just like for queries:
SELECT DISTINCT Description FROM Table
SELECT Description FROM Table GROUP BY Description
Here's a data source sample:
<asp:LinqDataSource ID="MyDataSource" runat="server"
Select="new (key as Targetitem, it as Participant_Targetitem_Associations)"