asp.net - Bind a list returned from a LINQ query to Gridview -


i have linq query this

var query = c in table             (some condition)             select new {             name = c.name,             courses = // returns list,             }; 

how bind gridview result this

name1 course1 name1 course2 name1 course3 name2 course1 name2 course2 

any ideas?

try below

gridview.datasource = query.tolist().select(a => a.courses              .select(c => new { name = a.name, course = c }))              .selectmany(p=>p).tolist(); gridview.databind(); 

if want return list method create class below

public class myclass {     public string name { get; set; }     public string course { get; set; } } 

now can return list

public list<myclass> mymethod() {     var query = c in table                 (some condition)                 select new {                 name = c.name,                 courses = // returns list,                 };      return query.tolist().select(a => a.courses             .select(c => new myclass{ name = a.name, course = c }))             .selectmany(p=>p).tolist(); } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -