Introduction
In this article, I will demonstrate how to display employee details using AngularJS in ASP.NET. I will upload the employee details using bootstrap 4 modal and insert them into a SQL database table and retrieve those using AngularJS and ASP.NET Web Service.
Step 1:Open SQL Server 2014 and create a database table.
- CREATE TABLE [dbo].[EmployeeDetails](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [Name] [nvarchar](50) NULL,
- [Position] [nvarchar](50) NULL,
- [Office] [nvarchar](50) NULL,
- [Profile_Picture] [nvarchar](50) NULL,
- CONSTRAINT [PK_EmployeeDetails] PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO
- CREATE ALTER procedure [dbo].[spAddEmployeeDetails]
- (
- @Name nvarchar(50),
- @Position nvarchar(50),
- @Office nvarchar(50),
- @Profile_Picture nvarchar(50)
- )
- as
- begin
- insert into [dbo].[EmployeeDetails](Name,Position,Office,Profile_Picture)
- values(@Name,@Position,@Office,@Profile_Picture)
- end
- CREATE procedure [dbo].[spGetEmployeeDetails]
- as
- begin
- select ID,Name,Position,Office,Profile_Picture from [dbo].[EmployeeDetails]
- end

Step 2:Open Visual Studio 2015, click on New Project, and create an empty web application project.
Screenshot for creating new project 1

After clicking on New Project, one window will appear. Select Web from the left panel, choose ASP.NET Web Application, give it a meaningful name for your project, then click on OK as shown in the below screenshot.
Screenshot for creating new project 2

After clicking on OK, one more window will appear. Choose Empty, check on Web Forms checkbox, and click on OK.
Screenshot for creating new project 3

Step 3: Double-click on webconfig file to add database connection.
- <connectionStrings>
- <add name="DBCS" connectionString="data source=DESKTOP-M021QJH\SQLEXPRESS; database=SampleDB; integrated security=true;"/>
- </connectionStrings>
Add the following code to get data.
- <system.web>
- <webServices>
- <protocols>
- <add name="HttpGet"/>
- </protocols>
- </webServices>
- </system.web>
Step 4: Right-click on Models folder, select Add, then choose a class and click.
Add C# class screenshot 1

After that, a window will appear. Choose class as shown in the below image. Give it the name EmployeeDetails and click on Add.
Add C# class screenshot 2

Write the following class.
- namespace DisplayEmployeeDetails_Demo.Models
- {
- public class EmployeeDetails
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Position { get; set; }
- public string Office { get; set; }
- public Nullable<int>Experience{ get; set; }
- public string Profile_Picture { get; set; }
- }
- }
Step 5: Right click on the project, select Add, then choose a new item and click on it.
Screenshot for Web Service 1

After that, a window will appear. Choose Web Service (ASMX). Give it a name as EmployeeService and click on Add.
Screenshot for Web Service 2

Add namespace
- using DisplayEmployeeDetails_Demo.Models;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.Web.Script.Serialization;
- using System.Web.Services;
- Write following code in web service
- [WebMethod]
- public void GetEmployeeDetails()
- {
- List<EmployeeDetails> employeeList = new List<EmployeeDetails>();
- string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
- using (SqlConnection con = new SqlConnection(CS))
- {
- SqlCommand cmd = new SqlCommand("spGetEmployeeDetails", con);
- cmd.CommandType = CommandType.StoredProcedure;
- con.Open();
- SqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- EmployeeDetails emp = new EmployeeDetails();
- emp.ID = Convert.ToInt32(rdr["ID"]);
- emp.Name = rdr["Name"].ToString();
- emp.Position = rdr["Position"].ToString();
- emp.Office = rdr["Office"].ToString();
- emp.Profile_Picture = rdr["Profile_Picture"].ToString();
- employeeList.Add(emp);
- }
- }
- JavaScriptSerializer js = new JavaScriptSerializer();
- Context.Response.Write(js.Serialize(employeeList));
- }
Complete web service code
- using DisplayEmployeeDetails_Demo.Models;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.Web.Script.Serialization;
- using System.Web.Services;
- namespace DisplayEmployeeDetails_Demo
- {
- /// <summary>
- /// Summary description for EmployeeService
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- // [System.Web.Script.Services.ScriptService]
- public class EmployeeService : System.Web.Services.WebService
- {
- [WebMethod]
- public void GetEmployeeDetails()
- {
- List<EmployeeDetails> employeeList = new List<EmployeeDetails>();
- string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
- using (SqlConnection con = new SqlConnection(CS))
- {
- SqlCommand cmd = new SqlCommand("spGetEmployeeDetails", con);
- cmd.CommandType = CommandType.StoredProcedure;
- con.Open();
- SqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- EmployeeDetails emp = new EmployeeDetails();
- emp.ID = Convert.ToInt32(rdr["ID"]);
- emp.Name = rdr["Name"].ToString();
- emp.Position = rdr["Position"].ToString();
- emp.Office = rdr["Office"].ToString();
- emp.Profile_Picture = rdr["Profile_Picture"].ToString();
- employeeList.Add(emp);
- }
- }
- JavaScriptSerializer js = new JavaScriptSerializer();
- Context.Response.Write(js.Serialize(employeeList));
- }
- }
- }
Step 6: Right click on the project, select Add, then choose Web Form and click on it.
Screenshot adding web form 1

After that, one window will appear. Give it the name EmployeeList and click on OK.
Screenshot adding web form 2

Add the following CDN link for style and script.
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
- <link href="EmployeeCard.css" rel="stylesheet" />
Write the script to retrieve data from the database.
- <script type="text/javascript">
- var app = angular
- .module("myModule", [])
- .controller("myController", function ($scope, $http) {
- $http.get("EmployeeService.asmx/GetEmployeeDetails")
- .then(function (response) {
- $scope.employees = response.data;
- });
- })
- </script>



Subhashkumar YadavPosted May 28, 2018, 12:38 AM
Hi can you explain this code <script type="text/javascript"> var app = angular .module("myModule", []) .controller("myController", function ($scope, $http) { $http.get("EmployeeService.asmx/GetEmployeeDetails") .then(function (response) { $scope.employees = response.data; }); }) </script>