Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
List of Array to datatable
Anoop Bansal
7y
242
1
Reply
Hi,
I have a class
public
class
AppUpdator
{
public
string
ApplicationName {
get
;
set
; }
public
Version CurrentVersion {
get
;
set
; }
public
Version InstalledVersion {
get
;
set
; }
public
DateTime ReleaseDate {
get
;
set
; }
public
StringBuilder Description {
get
;
set
; }
public
List<FileNames> filenames =
new
List<FileNames>()
;
}
public
struct
FileNames
{
public
string
FileName {
get
;
set
; }
public
string
DestinationFolder {
get
;
set
; }
public
byte
FileSize {
get
;
set
; }
public
enum
FileOperation
{
Copy,
Unzip,
Delete,
Execute
}
public
FileOperation Operation {
get
;
set
; }
public
string
DownloadURL {
get
;
set
; }
}
I use Generic to convert list to Datatable
public
DataTable CreateDataTable<T>(IEnumerable<T> list)
{
Type type =
typeof
(T);
var properties = type.GetProperties();
DataTable dataTable =
new
DataTable();
foreach
(PropertyInfo info
in
properties)
{
dataTable.Columns.Add(
new
DataColumn(info.Name, Nullable.GetUnderlyingType(info.PropertyType) ?? info.PropertyType));
}
foreach
(T entity
in
list)
{
object
[] values =
new
object
[properties.Length];
for
(
int
i = 0; i < properties.Length; i++)
{
values[i] = properties[i].GetValue(entity);
}
dataTable.Rows.Add(values);
}
return
dataTable;
}
But datatable doesnot return the list of files (as highlighted), it excludes the List<Filenames> variable and return only 5 columns to datatable.
How to include that
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Only selected item for combobox
How can I datalist paging with linq c#