2017-02-01 5 views
0

У меня есть этот GridView:как объединить столбцы с одинаковым значением в каждой строке GridView asp.net

enter image description here

Но это нужно:

enter image description here

Мне нужно объединить столбцы для каждой дороги, когда у них одинаковое значение !!! Я пытаюсь сделать расписание с gridview.

Большое спасибо за вашу помощь ...

+0

в эксперименте RowDataBoundEvent с 'ColumnSpan':' e.Row.Cells [X] .ColumnSpan' – fnostro

ответ

1

Вот решение, которое я сделал сам ...

Если кто-то нуждается в этом ...

for (int x = 0; x < e.Row.Cells.Count; x++) 
    { 
     // work out how wide the cell span should be for this cell 
     int span = 1; 
     while (

      (x + span < e.Row.Cells.Count) && 
      (e.Row.Cells[x + span].Text == e.Row.Cells[x].Text) && 
      (e.Row.Cells[x].Text != "&nbsp;") 
      ) 
     { 
      span++; 
     } 

     // if we need to span this cell 
     if (span > 1) 
     { 
      // apply the span value to the first cell in the group 
      e.Row.Cells[x].ColumnSpan = span; 

      for (int n = 1; n < span; n++) 
      { 
       while (n < span) 
       { 
        e.Row.Cells[x + span - n].Visible = false; 
        n++; 
       } 
      } 
      // skip to the next cell past the end of the span 
      x += span - 1; 
     } 
    }