I have a DataTable that was built from dynamically created SQL, so I do not know the number of columns in the datatable.
How can I convert this datatable into an IList?
EDIT: I am then going to use this to send to a Telerik Grid on the page.
I have a DataTable that was built from dynamically created SQL, so I do not know the number of columns in the datatable.
How can I convert this datatable into an IList?
EDIT: I am then going to use this to send to a Telerik Grid on the page.
You can create an IList<Dictionary<string, object>>
like this:
table.AsEnumerable()
.Select(r => table.Columns.ToDictionary(c => c.ColumnName, c => r[c]))
.ToList();
var list = new List<DataRow>();
foreach (var row in table.Rows)
list.Add(row);
return list;
To answer your edited question, you can simply bind the grid directly to the DataTable
. (Or to its DefaultView
)
You don't need a separate IList
.