Sunday, September 4, 2011

an example of using a DataTable with n number of columns in a Razor view

<table style="border: 1px solid black">

   <thead>

      <tr>

      @foreach (DataColumn column in table.Columns)

      {

         <th>@column.Caption</th>

      }

      </tr>

   </thead>

   <tbody>

      @foreach (DataRow row in table.Rows)

      {

         <tr>

         @foreach (var cell in row.ItemArray)

         {

            <td>@cell.ToString()</td>

         }

         </tr>

      }

   </tbody>

</table>

No comments:

Post a Comment