0

I have this code :

<asp:DropDownList AutoPostBack=False id="nation" runat="server" DataTextField="Title" DataValueField="Desc"></asp:DropDownList>

DataView nation = new DataView(new MyObjects().RsTable);
nation.Sort = "Title DESC";
DropNazioni.DataSource = nation;
DropNazioni.DataBind();

What I'd like to do is :

  1. Put only distinct values in the DropDownList (so if I have 2 values "Italy", insert only one time Italy);
  2. Upper the strings in the DropDownList (so if I have Italy, print ITALY);

Tried nation.Distinct() or nation.ToUpperString() but seems that these methods don't exists.

I'm on (unfortunatly) an old project, with .NET 2.0, so no LINQ.

markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 1
    LINQ on the .NET 2.0 Runtime - Take look at - http://stackoverflow.com/questions/2138/linq-on-the-net-2-0-runtime – KV Prajapati Feb 01 '12 at 11:53

2 Answers2

1

Try GroupBy.

var result = MyObjects().RsTable
                        .AsEnumerable()
                        .GroupBy(p => p.Field<string>("Nation"))
                        .Select(p=>p.Key);

Or

var result = MyObjects().RsTable
                        .AsEnumerable()
                        .GroupBy(p => p.Field<string>("Nation").ToUpper())
                        .Select(p=>p.Key);
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

Found a solution :

DropNazioni.DataSource = nation.ToTable(true,new string[] { "Title", "Desc" });

and CSS on DropDownList :

style="text-transform:uppercase;"
markzzz
  • 47,390
  • 120
  • 299
  • 507