foreach row in datatable add a asptablerow and asptablecell for each column

asp.net, c#, datatable

Solution

You have to use the `DataTable.Rows` property and the `DataTable.Columns` property:

foreach (DataRow DRow in dtEquipment.Rows)
{
    TableRow tRow = new TableRow();
    foreach (DataColumn dCol in dtEquipment.Columns)
    {
        // ...
        tCell.Text = DRow[dCol].ToString();
        // ...
    }
    tblTest.Rows.Add(tRow);
}

Problem

Im trying to programatically add rows to a asp:table below are my efforts thus far:- but datarow does not contain a getenumorator, i dont know what this means, can anyone help me out? i know using a repeater is easier but for this page i need a serverside table so im trying to do it this way, also how do i add the column data in the right order to match the tableheaders? ``` dtEquipment = new dsData.tblEquipmentDataTable(); taEquipment = new dsDataTableAdapters.tblEquipmentTableAdapter(); taEquipment.FillbyUser(dtEquipment); foreach (DataRow DRow in dtEquipment) { TableRow tRow = new TableRow(); foreach (DataColumn dCol in DRow) { TableCell tCell = new TableCell(); tCell.Text = DRow["AssetNo"].ToString(); tRow.Cells.Add(tCell); } tblTest.Rows.Add(tRow); } ```

Original source