这是我的HTML
代码:
<div id="page" class="page chartContainer">
<h1>Your Score is</h1>
<div class="progress-bar">
<canvas id="inactiveProgress" class="progress-inactive" height="275px" width="275px"></canvas>
<canvas id="activeProgress" class="progress-active" height="275px" width="275px"></canvas>
<p id="percentagediv" runat="server"></p>
</div>
<div id="progressControllerContainer" runat="server">
<input type="range" runat="server" id="progressController" min="0" max="200"/>
</div>
</div>
这是我从代码背后绑定价值的地方:<p id="percentagediv" runat="server"></p>
。这是我的C#
代码:
if (Convert.ToInt32(dt.Rows[0][1]) != 0 && Convert.ToInt32(dt.Rows[1][1]) != 0)
{
int achived = Convert.ToInt32(dt.Rows[0][1]);
int trget = Convert.ToInt32(dt.Rows[1][1]);
int percentage = (int)Math.Round((double)(100 * achived) / trget);
percentagediv.InnerHtml = percentage + "%";
}
else
{
percentagediv.InnerHtml = 0 + "%";
}
我调试了它的值percentagediv
,但在头版它显示为NaN
?这有什么不对?任何帮助将非常感激。谢谢!
您的问题是+运算符。 +被视为一元数学加法,并将尝试像javascript中的convert the string to a number。
你需要删除+并使用不同的方法,如String.Concat Method。
尝试
percentagediv.InnerHtml = String.Format("{0}%", percentage );