ASP.NET将多个页脚行添加到Gridview(ASP.NET Adding Multiple footers rows to Gridview)

编程入门 行业动态 更新时间:2024-10-25 21:17:48
ASP.NET将多个页脚行添加到Gridview(ASP.NET Adding Multiple footers rows to 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

如何添加更多页脚行,即总折扣,总保存等同样如上所述

i.e at the moment I am adding a footer row to my gridview as follows

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

How can I add more footer rows i.e. Total Discount, Total Saved etc likewise as above

最满意答案

这是一些基于页脚行插入新行的代码。 您可以修改它以插入多行。

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

Here's some code for inserting a new row, based on the footer row. You could modify it to insert multiple rows.

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

更多推荐

If,footer,Sub,Row,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-08-04 14:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   页脚行   ASP   NET   Gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!