Hi There,
I have a complex object that I'd like to bind to a GridView. As per code below, I need to display the Member Name, SSN, HoursPaid and a bunch of dynamic columns (payroll details), Ex:
Member Name = John Smith
SSS = 12345678
HoursPaid = 200
Retirement = 120.00
Health & Welfare = 50.00
RSP = 20.00
where Retirement, Health & Welfare, RSP are dynamic. I was able to the dynamic columns to show in the gridview, but I was not able to show the amount to display in the row. Here's the sample code I used
BindingList<MemberPayroll> memberList =
new
BindingList<MemberPayroll>();
.....
dgPayrollMembers.AutoGenerateColumns =
false
;
dgPayrollMembers.DataSource = memberList;
GridViewTextBoxColumn textBoxColumn =
new
GridViewTextBoxColumn();
textBoxColumn.HeaderText =
"Member"
;
textBoxColumn.FieldName =
"FullName"
;
textBoxColumn.MaxLength = 50;
textBoxColumn.Width = 200;
dgPayrollMembers.MasterTemplate.Columns.Add(textBoxColumn);
textBoxColumn =
new
GridViewTextBoxColumn();
textBoxColumn.HeaderText =
"SSN"
;
textBoxColumn.FieldName =
"SSN"
;
textBoxColumn.MaxLength = 50;
textBoxColumn.Width = 100;
dgPayrollMembers.MasterTemplate.Columns.Add(textBoxColumn);
textBoxColumn =
new
GridViewTextBoxColumn();
textBoxColumn.HeaderText =
"HoursPaid"
;
textBoxColumn.FieldName =
"HoursPaid"
;
textBoxColumn.MaxLength = 50;
textBoxColumn.Width = 100;
dgPayrollMembers.MasterTemplate.Columns.Add(textBoxColumn);
foreach
(PayrollDetail payrollDetail
in
payrollList)
{
textBoxColumn =
new
GridViewTextBoxColumn();
textBoxColumn.HeaderText = payrollDetail.Description;
textBoxColumn.FieldName =
"Payrolls.Amount"
;
textBoxColumn.MaxLength = 50;
textBoxColumn.Width = 90;
dgPayrollMembers.MasterTemplate.Columns.Add(textBoxColumn);
index++;
}
public
class
MemberPayroll
{
public
string
FullName
{
get
;
set
;
}
public
string
SSN
{
get
;
set
;
}
public
string
HoursPaid
{
get
;
set
;
}
public
BindingList<PayrollDetail> Payrolls
{
get
;
set
;
}
}
public
class
PayrollDetail
{
public
string
Description
{
get
;
set
;
}
public
string
Amount
{
get
;
set
;
}
}