0

This is my HTML code:

 <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>

This is where I'm binding value from code behind: <p id="percentagediv" runat="server"></p>. This is my C# code:

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 + "%";
    }

I have debugged it value coming in that percentagediv but on front page it is displaying as NaN? What is wrong here? Any help would be much appreciated. Thanks!

Dungeon
  • 972
  • 2
  • 16
  • 32

2 Answers2

0

Your issue is the + operator. The + is treated as a unary mathematical addition and will attempt to convert the string to a number like in javascript.

you need to remove the + and use different method like String.Concat Method.

Barr J
  • 10,636
  • 1
  • 28
  • 46
0

try

percentagediv.InnerHtml = String.Format("{0}%", percentage );
Arphile
  • 841
  • 6
  • 18
  • when you check Console.WriteLine( String.Format("{0}%", percentage) ); , is it shows what you expected? – Arphile Sep 05 '18 at 08:36
  • It is showing as e.g. `70%` which is showing in my case also in `console.writeline`. Problem is it is not displaying on page and just display `NaN` – Dungeon Sep 05 '18 at 09:20