我想使總列的總和作爲總計行數據總計。在rowdatabound事件中如何統計總數並在標籤中顯示?如何計算開往事件
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="gridview" DataKeyNames="Id" Width="633px" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
<asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" SortExpression="UnitPrice" />
<asp:BoundField DataField="Total" HeaderText="Total" SortExpression="Total" />
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int value = Convert.ToInt32(e.Row.Cells[2].Text);
int value2 = Convert.ToInt32(e.Row.Cells[3].Text);
int total = value * value2;
e.Row.Cells[4].Text = Convert.ToString(total);
int GrandTotal = +total;
lblgrandTotal = GrandTotal.ToString();
}
}
'總計'是什麼'總數'? –
是的。我想統計所有總數總和。我親切地更新過 –
在'protected'範圍之外取'int GrandTotal'。使其成爲不是本地的全局變量。 – Prabhat