Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Filas de la tabla Rowspan en C # HTML con 'For loop' basado en cierto valor

Me gustaría hacer un Rowspan en la primera columna de mi tabla.

Mi tabla actual se ve así:

Escribe Color número
Coche Rojo 1
Coche Negro 2
Coche Negro 3
Bicicleta Amarillo 4
Bicicleta Verde 5
Bicicleta Amarillo 6

Lo que quiero es fusionar todas las filas que tienen el mismo TIPO. Para este ejemplo, debería ingresar en la columna Tipo solo dos filas; Coche y Bicicleta. Sé cómo colapsar, pero la cosa es que obtengo mi tabla de una base de datos como esta:

 <table class="table table-striped table-bordered " style="display:inline-table;"> <thead> <tr > <th class="col-1"> Type </th> <th class="col-2"> Color </th> <th class="col-2"> Num </th> </tr> </thead> <tbody> @foreach (var item in Model) { <tr> <td> @item.Type </td> <td> @item.Color </td> <td> @item.Num </td> </tr> } </tbody> </table>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agrupa tus datos:

 <tbody> @foreach (var group in Model.GroupBy(i => i.Type)) { var items = group.ToList(); <tr> <td rowspan="@items.Count">@group.Key</td> <td>@items[0].Color</td> <td>@items[0].Num</td> </tr> @for (int index = 1; index < items.Count; index++) { <tr> <td>@items[index].Color</td> <td>@items[index].Num</td> </tr> } } </tbody>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!