Hi rani,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', []);
app.controller("MyController", function ($scope, $http) {
$http.post("Default.aspx/GetCustomers", { headers: { 'Content-Type': 'application/json'} })
.then(function (response) {
$scope.Customers = eval(response.data.d);
});
angular.element(document.querySelector('#dvPanel')).bind('scroll', function () {
var divScrollPosition = angular.element(document.querySelector('#dvPanel'))[0].scrollTop;
var customerTableHeight = angular.element(document.querySelector('#tblCustomers'))[0].clientHeight;
var divHeight = angular.element(document.querySelector('#dvPanel'))[0].clientHeight;
var scrollPercentage = (divScrollPosition / (customerTableHeight - divHeight)) * 100;
angular.element(document.querySelector('#dvProgress')).html(scrollPercentage.toFixed() + '%');
angular.element(document.querySelector('#dvProgress')).css('width', scrollPercentage.toFixed() + "%");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="MyApp" ng-controller="MyController">
<div id="dvProgress" style="height: 15px; background-color: Green; width: 0px; text-align: center;
color: White;">
</div>
<div id="dvPanel" style="overflow-y: scroll; height: 200px; width: 330px; border: 1px solid red;">
<table id="tblCustomers">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="customer in Customers">
<td>{{ customer.Id }}</td>
<td>{{ customer.Name }}</td>
<td>{{ customer.Country }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</body>
</html>
Namespaces
C#
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Web.Services;
VB.Net
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.Script.Serialization
Imports System.Web.Services
Code
C#
[WebMethod]
public static string GetCustomers()
{
List<object> customers = new List<object>();
string sql = "SELECT CustomerID,ContactName,Country FROM Customers";
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new
{
Id = sdr["CustomerID"],
Name = sdr["ContactName"],
Country = sdr["Country"]
});
}
}
conn.Close();
}
return (new JavaScriptSerializer().Serialize(customers));
}
}
VB.Net
<WebMethod()>
Public Shared Function GetCustomers() As String
Dim employees As List(Of Object) = New List(Of Object)()
Dim sql As String = "SELECT CustomerID,ContactName,Country FROM Customers"
Using conn As SqlConnection = New SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using cmd As SqlCommand = New SqlCommand(sql)
cmd.Connection = conn
conn.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
employees.Add(New With { _
.Id = sdr("CustomerID"),
.Name = sdr("ContactName"),
.Country = sdr("Country")
})
End While
End Using
conn.Close()
End Using
Return (New JavaScriptSerializer().Serialize(employees))
End Using
End Function
Screenshot