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 NairPosted Dec 18, 2010, 1:05 AM
if its 3.0 then change to 3.5 and complie the code.
Sam HobbsPosted Dec 17, 2010, 9:04 PM
Subhendu DePosted Dec 17, 2010, 5:22 AM
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();
Pravin GhadgePosted Dec 17, 2010, 3:54 AM
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;
Madhu KPosted Dec 17, 2010, 2:36 AM
http://www.c-sharpcorner.com/UploadFile/kannagoud/4170/
Manikavelu VelayuthamPosted Dec 17, 2010, 2:32 AM
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();
Manikavelu VelayuthamPosted Dec 17, 2010, 2:21 AM