我需要在 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();
}
}
但是错误来了:
输入字符串的格式不正确。