合并页脚行无法正常工作

本文关键字:常工作 工作 合并 | 更新日期: 2023-09-27 17:58:43

我有一个包含13列的网格视图。我想在页脚行中显示总预算。我想将单元格合并在一起,以便页脚行正确显示。下面是我的代码

grdBasicBudget.FooterRow.Cells(0).ColumnSpan = 7
    grdBasicBudget.FooterRow.Cells.RemoveAt(1)
    grdBasicBudget.FooterRow.Cells.RemoveAt(2)
    grdBasicBudget.FooterRow.Cells.RemoveAt(3)
    grdBasicBudget.FooterRow.Cells.RemoveAt(4)
    grdBasicBudget.FooterRow.Cells.RemoveAt(5)
    grdBasicBudget.FooterRow.Cells.RemoveAt(6)

虽然有13列,但如果删除第7列,则会出现索引超出范围的异常我想在的页脚行中显示这个

grdBasicBudget.FooterRow.Cells(0).Text = " GRAND TOTAL BUDGET :" + GrandTotBudget.ToString()

我的网格视图看起来像这个

 <asp:GridView ID="grdBasicBudget" runat="server" AutoGenerateColumns="false" ShowFooter="true"
        Width="1500px" Style="text-align: right; vertical-align: middle" HorizontalAlign="Center"
        HeaderStyle-BackColor="#ffffcc">
        <RowStyle HorizontalAlign="Right" />
        <Columns>
            <asp:BoundField HeaderText="Part" DataField="part" />
            <asp:BoundField HeaderText="Revisi" DataField="revisit" />
            <asp:BoundField HeaderText="Revision Date(m/d/y)" DataField="revision_date" />
            <asp:BoundField HeaderText="Year" DataField="year" />
            <asp:BoundField HeaderText="TYPE" DataField="type" />
            <asp:BoundField HeaderText="Task1" DataField="task" />
            <asp:BoundField HeaderText="Task2" DataField="task2" />
            <asp:BoundField HeaderText="Activity" DataField="activity" />
            <asp:BoundField HeaderText="Contractor" DataField="contract" />
            <asp:BoundField HeaderText="Tie" DataField="tie" />
            <asp:BoundField HeaderText="Planned_Amount($)" DataField="planned_amount" />
            <asp:BoundField HeaderText="Estimated Delivery Date" DataField="estimated_del_date" />
            <asp:BoundField HeaderText="Notes" DataField="notes" />
        </Columns>
    </asp:GridView>

我想在计划金额单元格下方显示计算的金额,并在金额后面显示总预算,所以我想要这样的东西:

grdBasicBudget.FooterRow.Cells(0).Text = " GRAND TOTAL BUDGET" + GrandTotBudget.ToString()

GrandTotBudget部分应始终显示在计划金额单元格下方。

我还试着用这种方式写代码:

Protected Sub grdBasicBudget_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdBasicBudget.RowDataBound
    Dim counter As Integer
    If e.Row.RowType = DataControlRowType.Footer Then
        For counter = 1 To grdBasicBudget.Columns.Count - 1
            e.Row.Cells.RemoveAt(counter)
        Next
        e.Row.Cells(0).ColumnSpan = grdBasicBudget.Columns.Count - 1
        e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Center
        e.Row.Cells(0).Text = "This is a test"
    End If
End Sub

计数器仍然在第7列停止。我知道我的网格视图有7列以上。我不知道为什么我在第7栏说参数超出范围用户代码未处理异常。

任何帮助都将不胜感激。

合并页脚行无法正常工作

尝试低于

For i As Integer = grdBasicBudget.Columns.Count - 1 To 1 Step -1
    grdBasicBudget.FooterRow.Cells.RemoveAt(i)
Next