我需要通过添加与通用列表中的对象对应的行来创建一个表(LINQ 以替换 TableRow 创建中的 foreach)。我们可以使用 foreach 循环按照下面列出的方式进行操作。我们如何在没有 foreach的情况下使用LINQ实现此功能?
注意:对象中的每个属性都需要添加一个表格单元格。
System.Web.UI.WebControls.Table tableControl = new Table();
foreach (FinancialTransaction transaction in transactionsList)
{
TableRow row = new TableRow();
TableCell cellLineNumber = new TableCell();
cellLineNumber.Text = Convert.ToString(transaction.Line);
row.Cells.Add(cellLineNumber);
TableCell cellEmpID = new TableCell();
cellEmpID.Text = Convert.ToString(transaction.EmpID);
row.Cells.Add(cellEmpID);
TableCell cellSSN = new TableCell();
cellSSN.Text = transaction.SSN;
row.Cells.Add(cellSSN);
tableControl.Rows.Add(row);
}