How to bind a List to a gridview?
Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error How to bind a List to a gridview? on this date .
I can’t find an answer anywhere… I have a List<string[]> populated like this:
... while (myReader.Read()) { string[] row = new string[myInt]; for (int i = 0; i < myInt; i++) { row[i] = myReader[i].ToString(); } myList.Add(row); } ...
How do I bind this list to a gridview with TemplateField columns?
Answer
An easier way is to create an anonymous class and bind that to your GridView. Example:
var query = from c in row select new { SomeProperty = c }; GridView.DataSource=query; GridView.DataBind();