aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Monday, December 6, 2010 Total Views:  

Yesterday developer asked me, distinct method on a column using linq is not woking. So, i have decided to wite this example in my blog to share with all of you. Let’s start

Open your Visual Studio 2008/2010 from File -> New -> New Web Site.


Following is the code of Default.aspx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:GridView ID="GridView1" runat="server">
       </asp:GridView>
   </div>
   </form>
</body>
</html>

Following is the code of Default.aspx.cs page.

protected void Page_Load(object sender, EventArgs e)
   {
       GridView1.DataSource = from i in getAllEmployee()
                              group i by i.FullName into temp1
                              select temp1.Key;
       GridView1.DataBind();
   }

   public List<Employee> getAllEmployee()
   {
       List<Employee> emp = new List<Employee>()
       {
           new Employee(){ ID=1, FullName="Aamir Hasan", Age=25 },
           new Employee(){ ID=2, FullName="Awais Ahmed", Age=21 },
           new Employee(){ ID=3, FullName="Saba khan", Age=11 },
           new Employee(){ ID=4, FullName="Mahwish Hasan", Age=18 },
           new Employee(){ ID=5, FullName="Hina", Age=26 },
           new Employee(){ ID=6, FullName="John", Age=24 },
           new Employee(){ ID=7, FullName="Aamir Hasan", Age=22 },
           new Employee(){ ID=8, FullName="Awais Ahmed", Age=21 },
           new Employee(){ ID=9, FullName="Aamir Hasan", Age=20 },
         };
       return emp;
   }

   public class Employee
   {
       public int ID { get; set; }
       public String FullName { get; set; }
       public int Age { get; set; }
   }


Note: You can get distinct values of any column by using above  linq query syntax.

Output

Download

Linq-Distinct-column-fetch-records.zip (1.11 kb)

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (18) -

Mahwish Akhtar
Mahwish Akhtar Canada
12/18/2010 1:47:01 AM #

I am now learning LINQ to SQL, after read this article

velatura
velatura United States
12/27/2010 6:50:37 PM #

Hi, i must say fantastic blog you have, i stumbled across it in Google. Does you get much traffic?

authentic prada bags
authentic prada bags United States
12/29/2010 6:41:06 PM #

Pretty good post. I just stumbled upon your blog and wanted to say that I have really
enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you
post again soon.?

chicago bears sweatshirt
chicago bears sweatshirt United States
1/4/2011 8:01:51 PM #

Awesome blog. Very informative. Your blog is very valuable from the blogger’s mind. Keep it up!

wipe credit card debt
wipe credit card debt United States
4/12/2011 1:02:27 AM #

Looking forward to the rest.

vehicle shipping rates
vehicle shipping rates United States
4/12/2011 1:44:09 AM #

this song makes me so happy, i've been having it stuck in my head ever since she posted it on her myspace.

moving companies st louis mo
moving companies st louis mo United States
4/13/2011 11:17:12 PM #

You prefab rattling fastidious points here. I performed a seek on the issue and observed virtually all peoples present concur with your journal.

locksmith spring tx
locksmith spring tx United States
4/14/2011 12:04:54 AM #

This cd is great! It's just..amazing!

fashionable laptop cases
fashionable laptop cases United States
4/14/2011 8:30:47 PM #

I am quite unputdownable in this substance desire you present careful statesman on it in upcoming posts.

mortgage
mortgage United States
4/15/2011 9:18:45 PM #

I same your journal curently we are looking for a line abstraction article communicator would you be interested?

cancer support
cancer support United States
4/15/2011 10:04:02 PM #

I judge you score to change a bit the system and usability of your journal.

auto transportation
auto transportation United States
4/18/2011 1:05:08 AM #

Wonderful illustrated entropy. I convey you some that. No doubt it module be very reusable for my emerging projects. Would equivalent to see both added posts on the selfsame matter!

contents insurance subsidence
contents insurance subsidence United Kingdom
5/5/2011 11:39:51 PM #

Good ue of codes here, although it might take a while to get my head around it.

male enhancement
male enhancement United States
10/24/2011 4:52:51 AM #

great post.. i really enjoyed it

Cheap Ugg Boots
Cheap Ugg Boots People's Republic of China
2/17/2012 7:59:08 PM #

http://www.ugg2me.net/ Cheap Ugg Boots
http://www.ugg2me.net/ Ugg Boots UK
www.ugg2me.net/ugg-boots-classic-short-c-4.html Ugg Boots Classic Short
www.ugg2me.net/ugg-boots-classic-tall-c-5.html Ugg Boots Classic Tall
www.ugg2me.net/ugg-boots-bailey-button-c-10.html Ugg Boots Bailey Button

wholesale cheap nfl jerseys
wholesale cheap nfl jerseys United States
3/5/2012 3:43:29 PM #

[url=http://www.b2b2bjerseys.com/]Gregg Williams[/url] who is the former [url=http://www.b2b2bjerseys.com/]New Orleans Saints[/url] defensive coordinator  will meet again with league security officials Monday in New York.
  The N.F.L. is expected to hand down harsh sanctions. It also said Loomis and Payton knew of the bounties and did nothing to stop   them, even though they violate N.F.L. rules. There are all kinds of [url=http://www.b2b2bjerseys.com/nfl-jerseys-c-1.html]new nfl football jerseys[/url] on sale include [url=http://www.b2b2bjerseys.com/nfl-jerseys-c-1.html]nike nfl jerseys[/url], [url=http://www.b2b2bjerseys.com/specials.html]wholesale cheap nfl jerseys[/url] and so on.

Buy&#160;Stromectol
Buy Stromectol United States
3/24/2012 12:27:10 AM #

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
www.westcoastdrugs.net/.../254.html

fddf
fddf People's Republic of China
3/31/2012 10:05:20 PM #

http://burberryoutlet-burberryscarf.com

Beats by dr dre outlet
Beats by dr dre outlet People's Republic of China
4/13/2012 3:41:04 PM #

Beats by dr dre outlet,Fashion personality,beats by dre for sale, smooth lines, bright colors,monster beats outlet, surround sound!
http://www.monsterbeats.ws/ beats by dr dre outlet
http://www.monsterbeats.ws/ beats by dre for sale
http://www.monsterbeats.ws/ monster beats outlet
http://www.monsterbeats.ws/beats-by-dr-dre-studio/ beats studio headphones
http://www.monsterbeats.ws/beats-by-dr_dre-pro/ beats by dr dre pro cheap
http://www.monsterbeats.ws/beats-by-dr_dre-solo/ beats by dre solo cheap
www.monsterbeats.ws/beats-by-dr_dre-solo-hd/ beats by dre solo hd for sale
http://www.monsterbeats.ws/beats-by-dr_dre-tour/ beats tour headphones control talk
http://www.monsterbeats.ws/beats-by-dr_dre-ibeats/ ibeats headphones with controltalk
www.monsterbeats.ws/beats-by-dr_dre-powerbeats/ powerbeats headphones
www.monsterbeats.ws/beats-by-dr_dre-diddybeats/ diddybeats in ear headphones
www.monsterbeats.ws/beats-by-dr_dre-heartbeats/ heartbeats by lady gaga cheap

Pingbacks and trackbacks (2)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5