【发布时间】:2015-04-13 15:20:55
【问题描述】:
我正在尝试将 Collection 转换为 DataTable,以便可以将其绑定到 gridview。 (如果有其他方法,我愿意接受)
这就是集合的样子:
public class CustomerCollection
{
[JsonProperty("customer")]
public IEnumerable<customer> Customer { get; set; }
}
public class customer
{
[JsonProperty("customer-name")]
public string strCustomerName { get; set; }
[JsonProperty("customer-address")]
public List<string> lCustomerAddress { get; set; }
}
最终结果如下所示:
我在尝试将其绑定到 gridview 时遇到的问题。我收到如下错误:
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
当使用 Helper 类尝试将其转换为 DataTable 时,我得到:
The type arguments for method 'CollectionHelper.ConvertTo<T>(System.Collections.Generic.IList<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
【问题讨论】:
标签: c# gridview collections datatable converter