In this article we will try to understand how to create a nested ListView in ASP.Net 3.5.
Step 1
Create an Address class as:
public class Address
{
public string Country
{
get;
set;
}
public string State
{
get;
set;
}
public string City
{
get;
set;
}
}
Step 2
Create a Customer Class as:
public class Customer
{
public string CustomerName
{
get;
set;
}
public string Email
{
get;
set;
}
public string Website
{
get;
set;
}
public List<Address> Address
{
get;
set;
}
}
Step 3
Create a Customer.aspx as:
<asp:ListView runat="server" ItemPlaceholderID="placeHolderCustomer" ID="LstCustomers">
<LayoutTemplate>
<div>
<asp:PlaceHolder runat="server" ID="placeHolderCustomer" />
</div>
</LayoutTemplate>
<ItemTemplate>
Customer Name:<asp:Label ID="Label1" Text='<%# Eval("CustomerName") %>' runat="server" /><br />
Email:<asp:Label ID="Label2" Text='<%# Eval("Email") %>' runat="server" /><br />
Website:<asp:Label ID="Label3" Text='<%# Eval("Website") %>' runat="server" />
<asp:ListView ID="ListView1" runat="server" DataSource='<%# Eval("Address") %>' ItemPlaceholderID="addressPlaceHolder">
<LayoutTemplate>
<div style="padding-left: 30px;">
<table border="1" cellpadding="0" cellspacing="0">
<asp:PlaceHolder runat="server" ID="addressPlaceHolder" />
</table>
</div>
<hr />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Label4" Text='<%# Eval("Country") %>' runat="server" />
</td>
<td>
<asp:Label ID="Label3" Text='<%# Eval("State") %>' runat="server" />
</td>
<td>

Lee RayPosted Jan 23, 2014, 8:00 PM
so awesome!
Rajendar reddyPosted Jan 6, 2013, 1:04 AM
great article.....Thanks http://www.microsoft-csharp-tutorials.com/post/2012/12/23/Listview-Control-in-Net-ItemInsert-in-Listview-ItemTemplate-and-AlternatingItemTemplate-in-Listview
Vithal WadjePosted Jan 1, 2013, 3:52 AM
super work
Mustafa IqbalPosted Oct 31, 2012, 5:11 AM
Thanks, your article is helpful for me, but one more thing confusing me, that how can I set image in listview from SQL datasource (Image is in binary format)?
Sandeep Singh ShekhawatPosted Oct 24, 2012, 12:29 AM
Thanks Sukesh to share this. I have some question if you have time pls explain these for me: 1. Why are you using LayoutTemplate for customer ListView? 2. Can you explain please Layout template working because table is defined in Layout Template but Rows and Columns are defines in ItemTemplate for Address ListView?