2016-08-05 23 views
0

我有一個gridview,我希望顯示標題爲「AccountManager」(列1)的列作爲行之間的標題/空間。如果名稱不同,以及每個賬戶管理器在每個「賬戶管理器」上方的空白/頭部中的列「總分」,「金額」和「利潤」的總和。在行之間插入標題如果Gridview中的名稱不同

這是我的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> 

請幫助...我soooooo麻煩米

+0

你說你想要的客戶經理姓名顯示一次,並且,直到它改變了項目的其餘部分是空白的? –

+0

是的......正好......在標題中,我希望僅顯示一次客戶經理名稱,直到其更改爲止......以及他的「分鐘」,「金額」和「利潤」的總和 –

回答

0

綜上所述值在頁腳,您可以使用此技術:

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 
+0

兄弟...我不希望總和在頁腳中,而是在爲每個帳戶管理器創建的後續動態行中......並且在c中也是這樣# –

+0

GridView控件不是用來提供像您所指的分組數據結構至。您可以使用像這樣的嵌套數據控件:http://www.asp.net/web-forms/overview/data-access/displaying-data-with-the-datalist-and-repeater/nested-data-網絡控制-CS –

相關問題