I want to convert the code below to a TableRow[]
array using LINQ and add it to a main Table
class.
foreach (DataRow dr in dt.Rows)
{
TableRow tr = new TableRow();
tr.Attributes.Add("onmouseover", "setMouseOverColor(this);");
tr.Attributes.Add("onmouseout", "setMouseOutColor(this);");
tr.Attributes.Add("onclick", "selectRow(this);");
TableCell td = new TableCell();
td.Text = dr["Test"].ToString();
tr.Cells.Add(td);
table.Rows.Add(tr);
}
Is there a way in LINQ to achieve this without going through a foreach
loop?
I was able to write a TableCell[]
array class as:
TableCell[] tdarr = dt.AsEnumerable().Select(p => new TableCell { Text = p.Field<string>("Test") }).ToArray();