Hi,
Please refer below sample
Index.aspx(View)
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("body").on("click", "[src*=plus]", function () {
$(this).attr("src", "../../Images/minus.png");
$(this).closest('tr').next('tr').show();
});
$("body").on("click", "[src*=minus]", function () {
$(this).attr("src", "../../Images/plus.png");
$(this).closest('tr').next('tr').hide();
});
});
</script>
<table class="Grid">
<tr>
<th>
</th>
<th>
CustomerId
</th>
<th>
Name
</th>
<th>
City
</th>
</tr>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<img id="imgShowHide" alt="" style="cursor: pointer" src="../../Images/plus.png" />
</td>
<td>
<%: item.CustomerId %>
</td>
<td>
<%: item.Name %>
</td>
<td>
<%: item.City %>
</td>
</tr>
<tr style="display: none">
<td>
</td>
<td colspan="999">
<table class="ChildGrid">
<tr>
<th>
Order Id
</th>
<th>
Order Date
</th>
</tr>
<% foreach (NestedRepeater.Models.Order order in NestedRepeater.Models.Order.GetOrders(item.CustomerId))
{ %>
<tr>
<td>
<%:order.OrderId %>
</td>
<td>
<%:order.OrderDate %>
</td>
</tr>
<%} %>
</table>
</td>
</tr>
<% } %>
</table>
</div>
CustomerController(Controller)
[HttpGet]
public ActionResult Index()
{
return View(Customer.GetCustomers());
}
Customer(Model)
public class Customer
{
public string CustomerId { get; set; }
public string Name { get; set; }
public string City { get; set; }
public static List<Customer> GetCustomers()
{
List<Customer> customers = new List<Customer>();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = string.Format("SELECT TOP 10 * FROM Customers");
cmd.Connection = con;
cmd.Connection.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new Customer
{
CustomerId = sdr["CustomerId"].ToString(),
Name = sdr["ContactName"].ToString(),
City = sdr["City"].ToString()
});
}
}
cmd.Connection.Close();
}
}
return customers;
}
}
Order(Model)
public class Order
{
public int OrderId { get; set; }
public DateTime OrderDate { get; set; }
public static List<Order> GetOrders(string customerId)
{
List<Order> orders = new List<Order>();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = string.Format("SELECT TOP 3 * FROM Orders WHERE CustomerId='{0}'", customerId);
cmd.Connection = con;
cmd.Connection.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
orders.Add(new Order
{
OrderId = Convert.ToInt32(sdr["OrderId"]),
OrderDate = Convert.ToDateTime(sdr["OrderDate"])
});
}
}
cmd.Connection.Close();
}
}
return orders;
}
}
Screenshot