TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Anoop Bansal
NA
58
6.2k
List of Array to datatable
Apr 22 2017 4:34 PM
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
Reply
Answers (
3
)
Menus & Submenus
How can I datalist paging with linq c#