2010-03-06 98 views

回答

-3

要做到這一點,你必須設置ShowFooter

屬性,然後在代碼在頁腳


<asp:GridView ID="grdList" runat="server" ShowFooter="True" > 
    // other part of gridview codes e.g columns or blah blah blah 
    </asp:GridView> 

    // in code-behind 
    int totalValue = 2 * 10; 
    grdList.Columns[2].FooterText = totalValue.ToString(); 
+0

我不能的找到這個屬性,我可以找到它? – Gold 2010-03-06 09:08:25

+0

@黃金我已更新我的帖子。一探究竟。 – 2010-03-06 09:18:02

+0

非常感謝!!但是我在WinForm上工作 也可以嗎? – Gold 2010-03-06 09:39:04

2

解決辦法其實很後面加上你的慾望值簡單,只需要你在盒子外面思考一下。

通常情況下,一旦數據被加載到你的網格視圖中,有一個暗灰色排在它的底部:

你可以使用這個空間,你的優勢。所有你需要做的就是拖幾個標籤到您的形式,放置只是你的網格視圖中,應用了背景色:

在你的代碼,添加這樣的方法:

void UpdateTotal(Label Label, int Number) 
{ 
    // Called from another thread; facilitate safe cross-thread operation 
    if(this.InvokeRequired) 
     this.Invoke(new Action<Label, int>(UpdateTotal), new object[] {Label, Number}); 

    // Called from this thread or invoked 
    else 
     // Format the number with a thousands separator 
     Label.Text = Number.ToString("N0"); 
} 

然後,無論您更新網格視圖的哪個位置,都可以使用您的標籤名稱以及您計算的總和(或在方法中計算出的總和)來調用​​。

的結果是這樣的:

0

是的,它是可能的。 首先,你必須迭代網格,並計算所需的列的總和 在計算總和後,你必須創建一個新的DataGridRow並用計算值填充它,將DataGridRow的Frozen屬性設置爲True,然後添加新的DataGridRow添加到Datagridview。 Sum Column Values in DataGridView

不是創建一個新DataGridRow你可以只添加一個新行與您的數據源上的總和值然後找到你的DataGrid中的最後一行,並設置該行的財產凍結=真