旅游网站策划方案,计算机网站开发面试问题及答案,html5做网站链接,国外建站工具后台数据绑定 用户场景是生成报表#xff0c;展示公司各员工每个月的绩效 数据结构 包括报表和单个员工绩效两个实体 public class Report
{/// summary/// 统计时间/// /summarypublic string StatisticalDate { get; set; }public ListReportDetail…后台数据绑定 用户场景是生成报表展示公司各员工每个月的绩效 数据结构 包括报表和单个员工绩效两个实体 public class Report
{/// summary/// 统计时间/// /summarypublic string StatisticalDate { get; set; }public ListReportDetail ReportDetails { get; set; }
} public class ReportDetail
{/// summary/// 职员姓名/// /summarypublic string EmployeeName { get; set; }/// summary/// 统计数据/// /summarypublic decimal Data { get; set; }
} 关键代码 DataGrid dataGrid new DataGrid();
var _ds new DataSet(Test);
Dt _ds.Tables.Add(月度绩效表);
//create columns
//创建列
Dt.Columns.Add(月份);
foreach (var item in reports[0].ReportDetails)
{Dt.Columns.Add(item.EmployeeName);
}
//fill data to rows
//赋值数据
for(int i0;i reports.Count;i)
{var theRow Dt.NewRow();theRow[0] reports[i].StatisticalDate;for (int j 0; j reports[i].ReportDetails.Count; j){theRow[j1] reports[i].ReportDetails[j].Data;}Dt.Rows.Add(theRow);
}
//数据绑定
dataGrid.ItemsSource Dt.AsDataView();
//将控件添加到Grid
MyGrid.Children.Add(dataGrid); 示例代码 https://github.com/zLulus/NotePractice/blob/dev3/WPF/WpfDemo/Bind/DataGridBackgroundBind.xamlhttps://github.com/zLulus/NotePractice/blob/dev3/WPF/WpfDemo/Bind/DataGridBackgroundBind.xaml.cs 其他列头重复解决方案 当前用户场景如果遇到行列互换即将员工姓名和月份互换可能出现列名相同的问题员工同名则最好将列头绑定改为员工姓名员工编号保证唯一性前端只显示名称绑定名称ID 前端数据绑定 数据结构 包括教师和教师信息扩展两个实体 public class Teacher
{public string SchoolNumber { get; set; }public string Name { get; set; }public string Sex { get; set; }public TeacherDetailInfo TeacherDetailInfo { get; set; }
} public class TeacherDetailInfo
{public DateTime EntryTime { get; set; }public string Address { get; set; }
} 关键代码 DataGrid ItemsSource{Binding } AutoGenerateColumnsFalse CanUserAddRowsFalseDataGrid.ColumnsDataGridTextColumn Header编号 Binding{Binding SchoolNumber}/DataGridTextColumn Header姓名 Binding{Binding Name}/DataGridTextColumn Header性别 Binding{Binding Sex}/!--格式化日期--DataGridTextColumn Header入职时间 Binding{Binding PathTeacherDetailInfo.EntryTime, StringFormat\{0:yyyy年MM月dd日\}}/!--如果这里是双向绑定则是下面的写法Mode是双向(TwoWay)触发器是变化即触发--!--DataGridTextColumn Header入职时间 Binding{Binding PathTeacherDetailInfo.EntryTime,ModeTwoWay,UpdateSourceTriggerPropertyChanged}/--DataGridTextColumn Header住址 Binding{Binding PathTeacherDetailInfo.Address}//DataGrid.Columns
/DataGrid 示例代码 https://github.com/zLulus/NotePractice/blob/dev3/WPF/WpfDemo/Bind/DataGridBindMultiData.xamlhttps://github.com/zLulus/NotePractice/blob/dev3/WPF/WpfDemo/Bind/DataGridBindMultiData.xaml.cs 转载于:https://www.cnblogs.com/Lulus/p/9726375.html