如果网格视图中的名称不同,则在行之间插入页眉
本文关键字:之间 插入 视图 网格 如果 | 更新日期: 2023-09-27 18:00:16
我有一个网格视图,我想在行之间显示标题为"AccountManager"的列(第1列)的Header/Space作为名称。如果名称不同,并且在每个"accountmanager"上方的空格/标题中每个帐户经理的"Mins"、"Amount"answers"Profit"列的总和。
这是我的GridView(HTML):
<asp:gridview runat="server" id="GridView2" showfooter="true"
autogeneratecolumns="false" GridLines="None" CssClass="table"
HeaderStyle-CssClass="th" RowStyle-CssClass="td" Width="100%" OnRowDataBound="GridView2_RowDataBound" onrowcreated="GridView2_RowCreated">
<columns>
<asp:boundfield datafield="Date" headertext="Date"
footerstyle-font-bold="true" >
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
<asp:boundfield datafield="AccountManager" headertext="AccountManager"
footerstyle-font-bold="true" >
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
<asp:boundfield datafield="" headertext="Total" footerstyle-font-bold="true"
footertext="Grand Total:" >
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
<asp:boundfield datafield="MIns" headertext="Mins"
footerstyle-font-bold="true" >
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
<asp:boundfield datafield="Amount" headertext="Amount" footerstyle-font-bold="true"
>
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
<asp:boundfield datafield="Profit" headertext="Profit"
footerstyle-font-bold="true">
<FooterStyle Font-Bold="True"></FooterStyle>
</asp:boundfield>
</columns>
<HeaderStyle BackColor="#CEFF99" ForeColor="Black" BorderColor="#C1FF80" BorderStyle="Solid"
BorderWidth="1px"></HeaderStyle>
<RowStyle CssClass="td"></RowStyle>
</asp:gridview>
请帮忙。。。我遇到麻烦了。
要对页脚中的值求和,可以使用以下技术:
在GridView的页脚中显示合计,并在最后一列中添加列的总和(行虎钳)。
为了不显示重复的列,如下所示(取自专家交流):
Protected Sub ResultGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles ResultGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'switch for first row
For j As Integer = 0 To 4
If e.Row.RowIndex = 1 Then
Dim Gprev As GridViewRow = ResultGridView.Rows(e.Row.RowIndex - 1)
If Gprev.Cells(j).Text.Equals(e.Row.Cells(j).Text) Then
e.Row.Cells(j).Text = ""
End If
End If
'now continue with the rest of the rows
If e.Row.RowIndex > 1 Then
'set reference to the row index and the current value
Dim intC As Integer = e.Row.RowIndex
Dim lookfor As String = e.Row.Cells(j).Text
'now loop back through checking previous entries for matches
Do
Dim Gprev As GridViewRow = ResultGridView.Rows(intC - 1)
If Gprev.Cells(j).Text.Equals(e.Row.Cells(j).Text) Then
e.Row.Cells(j).Text = ""
End If
intC = intC - 1
Loop While intC > 0
End If
Next
End If
End Sub