Hi avani,
I have created sample that full-fill your requirement.
Database
I’ll make use of Customers and Orders Table of Microsoft’s Northwind Database which you can easily download using the link provided below
HTML
<div>
<asp:ListView ID="lvCustomers" runat="server" DataKeyNames="CustomerID" DataMember="DefaultView"
ItemPlaceholderID="CustomerPlaceHolder">
<ItemTemplate>
<table>
<tr>
<th>
Customer ID:
</th>
<td>
<asp:Label ID="lblCustomerID" runat="server" Text='<%# Eval("CustomerID") %>' />
</td>
</tr>
<tr>
<th>
Company Name: </td>
<td>
<asp:Label ID="lblCompanyName" runat="server" Text='<%# Eval("CompanyName") %>' />
</td>
</tr>
<tr>
<th>
Country:
</th>
<td>
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>' />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ListView ID="lvOrders" runat="server" ItemPlaceholderID="itemPlaceholder2" DataSource='<%# getOrders(Eval("CustomerID").ToString()) %>'
DataKeyNames="CustomerID, OrderID">
<ItemTemplate>
<table>
<tr>
<th>
Order ID
</th>
<td>
<asp:Label ID="lblOrderID" CssClass="author" runat="server" Text='<%# Eval("OrderID") %>' />
</td>
</tr>
<tr>
<th>
Ship Name
</th>
<td>
<asp:Label ID="lblShipName" runat="server" Text='<%# Eval("ShipName") %>' />
</td>
</tr>
<tr>
<th>
Ship Address
</th>
<td>
<asp:Label ID="lblShipAddress" runat="server" Text='<%# Eval("ShipAddress") %>' />
</td>
</tr>
<tr>
<th>
Ship City
</th>
<td>
<asp:Label ID="lblShipCity" runat="server" Text='<%# Eval("ShipCity") %>' />
</td>
</tr>
</table>
</ItemTemplate>
<EmptyDataTemplate>
<b>There are no Order for this Customer</b>
</EmptyDataTemplate>
</asp:ListView>
</td>
</tr>
</table>
</ItemTemplate>
<EmptyDataTemplate>
No data found.
</EmptyDataTemplate>
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="CustomerPlaceHolder" />
</LayoutTemplate>
</asp:ListView>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindListView();
}
}
private void BindListView()
{
NorthwindEntities data = new NorthwindEntities();
var customers = from customer in data.Customers
orderby customer.CustomerID
select new
{
CustomerID = customer.CustomerID,
CompanyName = customer.CompanyName,
Country = customer.Country
};
lvCustomers.DataSource = customers.ToList();
lvCustomers.DataBind();
}
protected IQueryable getOrders(string CustomerID)
{
var data = new NorthwindEntities();
IQueryable orders = (from order in data.Orders
where order.CustomerID == CustomerID
orderby order.OrderID descending
select order).Take(2);
return orders;
}
Screenshot