如何将列表转换为数据表
[Serializable]
public class Item
{
public string Name { get; set; }
public double Price { get; set; }
public string @URL { get; set; }
public Item(string Name, string Price, string @URL)
{
this.Name = Name;
this.Price = Convert.ToDouble(Price);
this.@URL = @URL;
}
public override string ToString()
{
return this.Name;
}
}
我尝试使用:
static DataTable ConvertToDatatable(List<Item> list)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Price");
dt.Columns.Add("URL");
foreach (var item in list)
{
dt.Rows.Add(item.Name, Convert.ToString(item.Price), item.URL);
}
return dt;
}
现在我的页面上出现了一个空白的框,怎么办?帮帮我!我该怎么做才能让这个框显示数据呢?
itemDataView
是空的。它具体是什么并且它来自哪里?这看起来似乎是一个与将List<T>
转换为DataTable
的问题不同的问题。 - Alex Wiese