2011-08-16 60 views
3

即此刻我增加了腳註行到我的GridView如下ASP.NET添加多個頁腳行的GridView

Protected Sub gvShoppingCart_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvShoppingCart.RowDataBound 
    ' If we are binding the footer row, let's add in our total 
    If e.Row.RowType = DataControlRowType.Footer Then 
     e.Row.Cells(5).Text = "<strong>Total Cost:</strong>" 
     e.Row.Cells(6).Text = ShoppingCart.Instance.GetSubTotal().ToString("C") 
    End If 
End Sub 

我怎麼可以添加更多的註腳行,即總折扣,共保存等同樣作爲以上

回答

1

下面是基於頁腳行插入新行的一些代碼。您可以修改它以插入多行。

Protected Sub gvShoppingCart_DataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvShoppingCart.DataBound 
     Dim grid as GridView = CType(sender, GridView) 

     ''gets the current footer row to clone 
     Dim footer As GridViewRow = grid.FooterRow 
     Dim numCells = footer.Cells.Count 

     Dim newRow As New GridViewRow(footer.RowIndex + 1, -1, footer.RowType, footer.RowState) 

     ''have to add in the right number of cells 
     ''this also copies any styles over from the original footer 
     For i As Integer = 0 To numCells - 1 
      Dim emptyCell As New TableCell 
      emptyCell.ApplyStyle(grid.Columns(i).ItemStyle) 

      newRow.Cells.Add(emptyCell) 
     Next 

     newRow.Cells(5).Text = "Total Discount:" 
     newRow.Cells(6).Text = "55.00" 

     ''add new row to the gridview table, at the very bottom 
     CType(grid.Controls(0), Table).Rows.Add(newRow) 

    End Sub 
1

使用默認控件只有一個頁腳行,因此,您必須手動管理任何其他項目的顯示,很可能通過插入
或類似標籤來創建其他行。

您可以爲頁腳中的字段執行自定義模板以幫助控制佈局。