Hi Sudar,
Here i have created a sample by referring the below article. You can refer the sample and modify your code.
Database
For this sample I have used of NorthWind database that you can download using the link given below.
Download Northwind
HTML
<div ng-app="MyApp" ng-controller="MyController">
<input type="button" value="Generate Table" ng-click="ButtonClick()" />
<hr />
<table cellpadding="0" cellspacing="0" ng-show="IsVisible">
<tr>
<th>
Customer Id
</th>
<th>
Name
</th>
<th>
Country
</th>
<th>
Orders
</th>
</tr>
<tbody ng-repeat="c in Customers">
<tr>
<td>
{{c.CustomerId}}
</td>
<td>
{{c.Name}}
</td>
<td>
{{c.Country}}
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<th>
Order Id
</th>
<th>
Freight
</th>
<th>
ShipCountry
</th>
</tr>
<tbody ng-repeat="o in c.Orders">
<tr>
<td>
{{o.OrderId}}
</td>
<td>
{{o.Freight}}
</td>
<td>
{{o.ShipCountry}}
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $http, $window) {
$scope.ButtonClick = function () {
var post = $http({
method: "POST",
url: "CS.aspx/GetCustomerOrders",
dataType: 'json',
data: {},
headers: { "Content-Type": "application/json" }
});
post.success(function (data, status) {
$scope.IsVisible = false;
$scope.Customers = data.d;
$scope.IsVisible = true;
});
post.error(function (data, status) {
$window.alert(data.Message);
});
}
});
</script>
C#
static string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
[System.Web.Services.WebMethod]
public static List<Customer> GetCustomerOrders()
{
List<Customer> customers = new List<Customer>();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
con.Open();
cmd.CommandText = "SELECT TOP 5 CustomerId,ContactName,Country FROM Customers ORDER BY ContactName ASC";
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Customer customer = new Customer
{
CustomerId = rdr["CustomerId"].ToString(),
Name = rdr["ContactName"].ToString(),
Country = rdr["Country"].ToString(),
Orders = Orders(rdr["CustomerId"].ToString())
};
customers.Add(customer);
}
con.Close();
}
}
return customers;
}
public static List<Order> Orders(string customerId)
{
List<Order> orders = new List<Order>();
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
con.Open();
cmd.CommandText = "SELECT TOP 2 OrderId,Freight,ShipCountry FROM Orders WHERE CustomerId = @CustomerId";
cmd.Parameters.AddWithValue("@CustomerId", customerId);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Order order = new Order
{
OrderId = rdr["OrderId"].ToString(),
Freight = rdr["Freight"].ToString(),
ShipCountry = rdr["ShipCountry"].ToString(),
};
orders.Add(order);
}
con.Close();
}
}
return orders;
}
public class Customer
{
public string CustomerId { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public List<Order> Orders { get; set; }
}
public class Order
{
public string OrderId { get; set; }
public string Freight { get; set; }
public string ShipCountry { get; set; }
}
VB.Net
Shared strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
<System.Web.Services.WebMethod()> _
Public Shared Function GetCustomerOrders() As List(Of Customer)
Dim customers As New List(Of Customer)()
Using con As New SqlConnection(strConnString)
Using cmd As New SqlCommand()
cmd.Connection = con
con.Open()
cmd.CommandText = "SELECT TOP 5 CustomerId,ContactName,Country FROM Customers ORDER BY ContactName ASC"
Dim rdr As SqlDataReader = cmd.ExecuteReader()
While rdr.Read()
Dim customer As New Customer() With { _
.CustomerId = rdr("CustomerId").ToString(), _
.Name = rdr("ContactName").ToString(), _
.Country = rdr("Country").ToString(), _
.Orders = Orders(rdr("CustomerId").ToString()) _
}
customers.Add(Customer)
End While
con.Close()
End Using
End Using
Return customers
End Function
Public Shared Function Orders(customerId As String) As List(Of Order)
Dim orders_1 As New List(Of Order)()
Using con As New SqlConnection(strConnString)
Using cmd As New SqlCommand()
cmd.Connection = con
con.Open()
cmd.CommandText = "SELECT TOP 2 OrderId,Freight,ShipCountry FROM Orders WHERE CustomerId = @CustomerId"
cmd.Parameters.AddWithValue("@CustomerId", customerId)
Dim rdr As SqlDataReader = cmd.ExecuteReader()
While rdr.Read()
Dim order As New Order() With { _
.OrderId = rdr("OrderId").ToString(), _
.Freight = rdr("Freight").ToString(), _
.ShipCountry = rdr("ShipCountry").ToString() _
}
orders_1.Add(order)
End While
con.Close()
End Using
End Using
Return orders_1
End Function
Public Class Customer
Public Property CustomerId() As String
Get
Return m_CustomerId
End Get
Set(value As String)
m_CustomerId = value
End Set
End Property
Private m_CustomerId As String
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Name As String
Public Property Country() As String
Get
Return m_Country
End Get
Set(value As String)
m_Country = value
End Set
End Property
Private m_Country As String
Public Property Orders() As List(Of Order)
Get
Return m_Orders
End Get
Set(value As List(Of Order))
m_Orders = value
End Set
End Property
Private m_Orders As List(Of Order)
End Class
Public Class Order
Public Property OrderId() As String
Get
Return m_OrderId
End Get
Set(value As String)
m_OrderId = value
End Set
End Property
Private m_OrderId As String
Public Property Freight() As String
Get
Return m_Freight
End Get
Set(value As String)
m_Freight = value
End Set
End Property
Private m_Freight As String
Public Property ShipCountry() As String
Get
Return m_ShipCountry
End Get
Set(value As String)
m_ShipCountry = value
End Set
End Property
Private m_ShipCountry As String
End Class
Screenshot