I am running a SQL Query and returning the results to a gridview. I want to display the Totals in the footer row of the gridview. Everything works perfect,e xcept for a column that I am formatting as a % in the gridview. This is how I format it as a percetage
<asp:BoundField DataField="percentage" HeaderText="P" DataFormatString="{0:P}" />
And it throws the error message of:
input string was not in correct format
This is how I am calling it
protected void analysispack1_DataBound(object sender, EventArgs e)
{
if (analysispack1.Rows.Count > 0)
{
decimal showit = 0;
foreach (GridViewRow row in analysispack1.Rows)
{
showit += Convert.ToDecimal(row.Cells[2].Text);
}
try { analysispack1.FooterRow.Cells[0].Text = tmpDailAttendance.ToString(); }
catch (Exception exception) { throw exception; }
}
}
Change your code like this
foreach (GridViewRow row in analysispack1.Rows)
{
showit += Convert.ToDecimal(row.Cells[2].Text.Replace("%", string.Empty));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.