Iam using VS 2008
I want to add country in Dropdownlist.
I have used following code:
List<string> Country = GetCountryList();
var sortedCountry = from c in Country orderby c select c;
// var sortedCountry = from c in Country orderby c select c;
ddlCountry.DataSource = sortedCountry;
ddlCountry.DataBind();
But iam facing error on line:var sortedCountry = from c in Country orderby c select c;
I have also used foll. namespaces:
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Loading


Suthish NairRank #92 · 22.8K reputationPosted Dec 17, 2010, 8:05 PM EST
if its 3.0 then change to 3.5 and complie the code.
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 16, 2010, 9:21 PM EST
Manikavelu VelayuthamRank #413 · 6K reputationPosted Dec 16, 2010, 9:32 PM EST
Below code works fine, just try this;
List<string> s = new List<string>();
s.Add("Manik");
s.Add("Babu");
s.Add("Velu");
var s1 = from s2 in s orderby s2 select s2;
DropDownList1.DataSource = s1;
DropDownList1.DataBind();
Madhu KRank #1,514 · 1.1K reputationPosted Dec 16, 2010, 9:36 PM EST
http://www.c-sharpcorner.com/UploadFile/kannagoud/4170/
Pravin GhadgeRank #1,340 · 1.3K reputationPosted Dec 16, 2010, 10:54 PM EST
Error 2 ; expected
Error 3 ; expected
Error 4 Invalid expression term 'in'
Error 5 ; expected
Error 6 ; expected
Error 7 ; expected
on line:
var sortedCountry = from c in Country orderby c select c;
Subhendu DeRank #1,108 · 1.7K reputationPosted Dec 17, 2010, 12:22 AM EST
IList
_country.Add("India");
_country.Add("US");
_country.Add("China");
_country.Add("Zimbabwe");
var query = from c in _country
orderby c
select c;
DropDownList1.DataSource = query;
DropDownList1.DataBind();
Sam HobbsRank #107 · 20.5K reputationPosted Dec 17, 2010, 4:04 PM EST