Thursday, October 7, 2010

Create Table From Class Files With There Propertys/ Convert GenericList to DataTable

DataTable dt = GetDataTable(_PageInfo);

private DataTable GetDataTable(PageEntriesInfo _PageInfo)
{
var dt = new DataTable();

foreach (var Info in typeof(CustomElementInfo).GetProperties())
{
dt.Columns.Add(new DataColumn(Info.Name, Info.PropertyType));
}

foreach (var t in _PageInfo.CustomElements)
{
//CustomElements are SubCategory List
var row = dt.NewRow();
foreach (var Info in typeof(CustomElementInfo).GetProperties())
{
row[Info.Name] = Info.GetValue(t, null);
}
dt.Rows.Add(row);
}
return dt;
}

No comments:

Post a Comment