2
我使用下面的代碼來獲得DataField="Quantity"
在GridView的總和,並顯示在GridView頁腳標題文本變爲零
的問題HeaderText="Quantity"
變爲零
protected void griddelverynote_RowDataBound(object sender, GridViewRowEventArgs e)
{
int TotalQuantity = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
TotalQuantity += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Quantity"));
else if (e.Row.RowType == DataControlRowType.Footer)
e.Row.Cells[1].Text = "Total Quantity";
e.Row.Cells[2].Text = TotalQuantity.ToString();
}
謝謝,但我仍然有問題 – Ayman
@Ayman - Got it!你錯過了else if塊中的花括號。檢查答案。 –
同樣的問題HeaderText = 0 – Ayman