2016-10-01 3 views
0

enter image description here동적 그리드 뷰를 만드는 방법은 무엇입니까?

나는 그리드 뷰를 이와 같이 보길 원한다.

이 내 의제 표입니다 : 나는 위의 그림에서와 같이 볼 수있는 그리드 뷰/테이블을 만드는 방법을 enter image description here

. 저는 이전에 단순한 그리드 뷰를 사용하여 데이터 소스에 바인딩했지만 그 이상입니다.

답변

0

GridSpan 및 ColSpan을 GridView에서 프로그래밍 방식으로 사용할 수 있습니다. GridView의 OnRowDataBound 이벤트를 사용해야합니다.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     //chech if the row is the header 
     if (e.Row.RowType == DataControlRowType.Header) 
     { 
      //span 3 columns, starting with the first one (0) 
      e.Row.Cells[0].ColumnSpan = 3; 

      //remove the other 2 column cells 
      e.Row.Cells.RemoveAt(2); 
      e.Row.Cells.RemoveAt(1); 
     } 
     //check if the row is a datarow 
     else if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      //the last rownumber of the rows to be spanned, can only count backwards because next row does not exist yet. 
      if (e.Row.RowIndex == 8) 
      { 
       //amount of rows to be spanned 
       int rowSpanCount = 4; 

       //find the first cell counting backwards (8 - rowSpanCount) 
       GridViewRow firstRow = GridView1.Rows[e.Row.RowIndex - rowSpanCount]; 
       firstRow.Cells[1].RowSpan = rowSpanCount; 

       //hide the other cells that are part of the rowspan 
       for (int i = 1; i < rowSpanCount; i++) 
       { 
        GridViewRow nextRow = GridView1.Rows[e.Row.RowIndex - i]; 
        nextRow.Cells[1].Visible = false; 
       } 
      } 
     } 
    } 

니핏 내에서 HeaderRow 4 행에 걸쳐 모든 3 열 및 셀 4, 1 열에 걸쳐 것이다.

관련 문제