2012-12-06 1 views
1

내 코드에서 일부 gridviews 동적으로 만듭니다. 이러한 각 gridviews에 대해 각 열의 합계가있는 footerrow를 표시하려고합니다. 어떻게해야합니까? 어떻게 동적으로 생성 된 gridview의 바닥 글에 총계를 계산할 수 있습니까?

이있는 GridViews을 만드는 내 코드입니다 :

당신은 각 데이터 행에 대한 rowDataBound 이벤트에 총하고자하는 열을 총 다음 동일한에서 바닥 글 행의 합계를 삽입해야
  gv_arr(chart_count) = New GridView 
      gv_arr(chart_count).ID = "gv" & chart_count.ToString 
      gv_arr(chart_count).DataSource = dt 
      If statistieksoort = LnxEnum.EBIChartType.DataGridView Then 'DataGridView 
       gv_arr(chart_count).Visible = True 

       'Footer voor de totalen tonen indien nodig 
       gv_arr(chart_count).ShowFooter = True      
      Else 
       gv_arr(chart_count).Visible = objBichart.ShowGridView 
      End If 
      gv_arr(chart_count).DataBind() 

답변

0

행사.

Protected Sub gridDetails_RowDataBound(ByVal sender As Object, ByVal e As Obout.Grid.GridRowEventArgs) Handles gridDetails.RowDataBound 
      If e.Row.RowType = GridRowType.DataRow Then 
       subTotal+= {column with subtotal value} 
       taxTotal += {column with tax value} 
       discountTotal += {column with discount value} 
      ElseIf e.Row.RowType = GridRowType.ColumnFooter Then 
       Dim totalText1 As String = String.Empty 
       Dim totalText2 As String = String.Empty 
       grandTotal = subTotal + taxTotal + discountTotal 
       totalText1 = "Subtotal:<br />Tax:<br />Disc/Surc:<br />Total:" 
       totalText2 = String.Format("{0}<br />{1}<br />{2}<br />{3}", subTotal.ToString("c"), taxTotal.ToString("c"), discountTotal.ToString("c"), grandTotal.ToString("c")) 

       e.Row.Cells(5).Text = totalText1 
       e.Row.Cells(6).Text = totalText2 
      End If 
     End Sub 

나는 이것이 대략 95 %의 시간 동안 효과가 있다는 것을 발견했다. 이상한 바인딩을 다루는 경우, 데이터 합계 이벤트를 조사해야 할 수도 있습니다. 총 변수는 전역 범위입니다.

+0

답변 해 주셔서 감사합니다.하지만 여전히 문제가 있습니다. 여러 gridviews가 있기 때문에 어떻게 각 gridviews에 rowDataBound 이벤트를 연결할 수 있습니까? – user1882771

관련 문제