2009-04-30 7 views
4

데이터 세트로 바인딩 된 GridView가 있습니다. 나는 꼬리말을 가지고 있는데, 이는 칼럼 라인으로 구분된다. 2 개의 열을 병합하고 싶습니다. 어떻게해야합니까?바닥 글을 GridView에 병합 할 수 있습니까?

<asp:TemplateField HeaderText="Name" SortExpression="Name"> 
<ItemTemplate> 
... 
</ItemTemplate> 
<FooterTemplate >      
Grand Total: 
</div> 
</FooterTemplate> 
</asp:TemplateField> 
<asp:TemplateField HeaderText="Age" SortExpression="Age"> 
<ItemTemplate> 
... 
</ItemTemplate> 
<FooterTemplate >      
<%# GetTotal() %> 
</div> 
</FooterTemplate> 
</asp:TemplateField> 
+0

에 인덱스 세포에 액세스 할 수 대괄호를 사용하는 데 필요한 ... - http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2006/06/23/141038.aspx - http://forums.asp.net/t/1270422.aspx – madcolor

답변

2

테스트되지 않은 코드

1 바닥 글 템플릿 # GetTotal() %>

2 바닥 글 템플릿 <퍼센트 내가 이런 일을하고 있었다

Protected Sub Page_SaveStateComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SaveStateComplete 
     Dim DG As GridView = GridView1 
      Dim Tbl As Table = DG.Controls(0) 
      Dim tr As GridViewRow 
      Dim i As Integer 
      Dim j As Integer 

tr = Tbl.Rows(Tbl.Rows.Count - 1) 'this line assume last row is footer row 

        tr.Cells(0).ColumnSpan = 2 'if you have 3 columns then colspan = 3 instead 

        For j = 1 To 1 'if you have 3 columns then j = 1 To 2 instead 
         tr.Cells(j).Visible = False 
        Next 

    End Sub 
1

비어 있어야 포함해야한다 - 바닥 글에 여러 개의 열을 포함하는 버튼이 있습니다.

코드를 통해 columnspan을 설정했을 때 문제가 발생했습니다. 왜냐하면 a) 저는 멍청이이고 b)는 이 아니기 때문에 제가 예상했던대로이었습니다. 나는 모든 세부 사항을 기억하지 못한다. 그러나 거기에 어떤 종류의 잡화가 있었다. 그것은 여분의 기둥이나 뭔가를 추가하는 것과 같았다.

내 해결책은 여기에 있습니다. 어쩌면 그 중 일부가 유용 할 것입니다. gridview (gvDocs)의 프리렌더에서 했어요.

내게 제대로 작동하는 이유는 프로그래밍 방식으로 바닥 글의 셀을 제거하고 columnspan을 설정하기 위해서였습니다.

코드가 도움이되지 않더라도, 사람들은 저를 괴롭히는 잊혀진 망각에 대해 웃을 것입니다. 때때로 나를 웃게합니다.

Protected Sub gvDocs_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvDocs.PreRender 

     If gvDocs.Rows.Count > 0 Then 


      Dim m As Integer = gvDocs.FooterRow.Cells.Count 
      For i As Integer = m - 1 To 1 Step -1 
       If i <> 8 Then '7 is the number of the column with the applychanges button in it. 
        gvDocs.FooterRow.Cells.RemoveAt(i) 
       End If 
      Next i 
      gvDocs.FooterRow.Cells(1).ColumnSpan = 6 '6 is the number of visible columns to span. 
     End If 
    End Sub 

Fernando68는 - 여기가 C 번호에

protected void gvDocs_PreRender(object sender, System.EventArgs e) 
{ 

    if (gvDocs.Rows.Count > 0) { 

     int m = gvDocs.FooterRow.Cells.Count; 
     for (int i = m - 1; i >= 1; i += -1) { 
      //7 is the number of the column with the applychanges button in it. 
      if (i != 8) { 
       gvDocs.FooterRow.Cells.RemoveAt(i); 
      } 
     } 
     gvDocs.FooterRow.Cells[1].ColumnSpan = 6; 
     //6 is the number of visible columns to span. 
    } 
} 

//======================================================= 
//Service provided by Telerik (www.telerik.com) 
//Conversion powered by NRefactory. 
//Twitter: @telerik 
//Facebook: facebook.com/telerik 
//======================================================= 

수정 됨 - 당신은 ColumnSpan 찾고있는 바닥 글 행

+0

C# version please? – Fandango68

+1

@ Fernando68 - C# – aape

+1

수정 해 주셔서 감사합니다. Mike Gray. – aape

6
protected void GridView1_OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) 
    { 

     if (e.Row.RowType == DataControlRowType.Footer) 
     { 
      e.Row.Cells.RemoveAt(1); 
      e.Row.Cells[0].ColumnSpan = 2; 

     } 

    } 
+0

아주 좋고 깔끔한 노력. –

관련 문제