Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
how can i bind gridview to list<>:
what i have done is as follows:
C#
var NameList = (from r in dataset.Tables[0].AsEnumerable()
                               select new
                               {
                                   Name = r.Field<string>("name"),
                                   Age = r.Field<string>("age"),
                                   Salary = r.Field<string>("salary"),
                                   City = r.Field<string>("city")
                               }).ToList(string);
               return  NameList;

error is coming like :
Quote:
Error 1 Invalid expression term 'string' d:\substituteofsqlhelp (2)\datalayer\DataLayer.cs 50 49 datalayer

why ?
what i had done earlier was :
//List<string> NameList = (from r in dataset.Tables[0].AsEnumerable()
              //                         select r.Field<string>("name")+ r.Field<string>("age")+r.Field<string>("salary")+r.Field<string>("city")).ToList();
              //return NameList;

but gives concatenated output. after AMY's help i wrote above code but again error was coming list like:
Quote:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<anonymoustype#1>' to 'System.Collections.Generic.List<string>' d:\substituteofsqlhelp (2)\datalayer\DataLayer.cs 51 25 datalayer

how can i solve the problem . Thanx.
Posted

1 solution

 
Share this answer
 
Comments
Herbisaurus 12-Aug-13 2:48am    
*****
ridoy 12-Aug-13 3:45am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900