I try to get distinct values in LINQ i try this for this first i create method and then i call this method on page load and assign
regiondrop.DataSource = getregion();
regiondrop.DataSourc=DataTextField="Region"
regiondrop.DataSourc==DataTextField="RID"
private List<tab1> getregion()
{
using (T1 tee = new T1())
{
var tempList = tee.tbl1.ToList();
var list = (from ta in tempList
select new { ta.Region, ta.RID }).Select(x => new tbl1
{
Id = x.RID,
reg=x.Region
}).ToList();
return list;
}
}
Data in db like this
RID Region
1 Canada
2 UK
3 London
4 Paris
5 UK
6 Brazil
7 London
Data in drop-down like this
Canada
UK
London
Paris
UK
Brazil
London
but i want data like this
Canada
UK
London
Paris
Brazil
any solution?
You can add a GroupBy
var list = from ta in tempList
group ta by ta.Region into g
select g.FirstOrDefault();
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