ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Calculate Running Total in HTML Table using AngularJS in ASP.Net<p>Hi&nbsp;skp,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>I have used web method to populate the record. You have to use Web API for this.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#39;MyApp&#39;, []); app.controller(&#39;MyController&#39;, function ($scope, $http) { $scope.Products = []; $http.post(&#34;Default.aspx/GetProducts&#34;, { headers: { &#39;Content-Type&#39;: &#39;application/json&#39;} }) .then(function (response) { $scope.Products = JSON.parse(response.data.d); }); $scope.Calculate = function (index) { $scope.Products[index].Total = parseFloat($scope.Products[index].Price) * parseFloat($scope.Products[index].Quantity); $scope.$apply(); } }); &lt;/script&gt; &lt;div ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Price&lt;/th&gt; &lt;th&gt;Quantity&lt;/th&gt; &lt;th&gt;Total&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr ng-repeat=&#34;product in Products&#34;&gt; &lt;td&gt;{{ product.Id }}&lt;/td&gt; &lt;td&gt;{{ product.Name }}&lt;/td&gt; &lt;td&gt;{{ product.Price }}&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;number&#34; min=&#34;0&#34; ng-model=&#34;product.Quantity&#34; ng-init=&#34;product.Quantity=0&#34; ng-change=&#34;Calculate($index)&#34; /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;number&#34; ng-model=&#34;product.Total&#34; ng-init=&#34;product.Total=0&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Web.Script.Serialization; using System.Web.Services;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Collections.Generic Imports System.Configuration Imports System.Data.SqlClient Imports System.Web.Script.Serialization Imports System.Web.Services </pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">[WebMethod] public static string GetProducts() { List&lt;object&gt; products = new List&lt;object&gt;(); string sql = &#34;SELECT TOP 5 ProductID,ProductName,UnitPrice FROM products&#34;; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlCommand cmd = new SqlCommand(sql)) { cmd.Connection = conn; conn.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { products.Add(new { Id = sdr[&#34;ProductID&#34;], Name = sdr[&#34;ProductName&#34;], Price = sdr[&#34;UnitPrice&#34;] }); } } conn.Close(); } return (new JavaScriptSerializer().Serialize(products)); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">&lt;WebMethod()&gt; Public Shared Function GetProducts() As String Dim products As List(Of Object) = New List(Of Object)() Dim sql As String = &#34;SELECT TOP 5 ProductID,ProductName,UnitPrice FROM products&#34; Using conn As SqlConnection = New SqlConnection() conn.ConnectionString = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using cmd As SqlCommand = New SqlCommand(sql) cmd.Connection = conn conn.Open() Using sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read() products.Add(New With { .Id = sdr(&#34;ProductID&#34;), .Name = sdr(&#34;ProductName&#34;), .Price = sdr(&#34;UnitPrice&#34;) }) End While End Using conn.Close() End Using Return (New JavaScriptSerializer().Serialize(products)) End Using End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/i0GE94R.gif" alt="" width="472" height="153" /></span></strong></p>https://www.aspforums.net:443/Threads/653139/Calculate-Running-Total-in-HTML-Table-using-AngularJS-in-ASPNet/https://www.aspforums.net:443/Threads/653139/Calculate-Running-Total-in-HTML-Table-using-AngularJS-in-ASPNet/Thu, 11 Jul 2019 07:08:58 GMT