我需要在gridview中設置一個特定列的總數。如何在C#中的GridView的頁腳中設置特定列的總數?
我的代碼是:
<asp:TemplateField>
<HeaderTemplate>
Amount
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblAmt" HeaderText="Amount" runat="server"
Text='<%# Eval("Amount")%>' Visible="true">
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotalAmt" runat="server" />
</FooterTemplate>
</asp:TemplateField>
然後:
decimal totProfit = 0M;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblAmt = (Label)e.Row.FindControl("lblAmt");
decimal Profitprice = Decimal.Parse(lblAmt.Text);
totProfit += Profitprice;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalAmt = (Label)e.Row.FindControl("lblTotalAmt");
lblTotalAmt.Text = totProfit.ToString();
}
}
不過來了錯誤,如:
輸入字符串的正確的格式是不是。