【问题标题】:Insert Header Between rows If name Is Different in Gridview如果 Gridview 中的名称不同,则在行之间插入标题
【发布时间】:2016-08-05 10:24:17
【问题描述】:

我有一个网格视图,我想显示标题/空格,其中列标题为“AccountManager”(第 1 列)作为行之间的名称。如果名称不同,并且每个“AccountManager”上方的空间/标题中每个 accountmanager 的“Mins”、“Amount”和“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>

请帮助...我遇到了麻烦。

【问题讨论】:

  • 您是说您希望客户经理姓名显示一次,其余条目为空白,直到更改?
  • 是的...正是...在标题中我只想显示一次客户经理姓名,直到它改变...以及他的“分钟”、“金额”和“利润”在哪里结束

标签: c# asp.net gridview


【解决方案1】:

要对页脚中的值求和,您可以使用以下技术:

Displaying Total in Footer of GridView and also Add Sum of columns(row vise) in last Column .

为了不显示重复的列,像这样 (taken from Experts Exchange):

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

【讨论】:

  • 兄弟...我不想在页脚中求和,而是在为每个帐户管理器单独创建之后创建的动态行中求和...在 c# 中也是如此
  • GridView 控件不是为提供您所指的分组数据结构而构建的。您也许可以像这样使用嵌套数据控件:asp.net/web-forms/overview/data-access/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-05
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多