Sample code
<asp:Repeater>
<ItemTemplate>
<asp:ListView DataSource=<%# Container.DataItem.Items %> ... />
<asp:DataPager .... />
</ItemTemplate>
</asp:Repeater>
This does not work.
The repeater data source is not a datasource control
It is set like so
repeater.DataSource = datasource
repeater.DataBind()
It is possible, and I’ve done it many times before.
You may have to wire up the events yourself, and you do have to use
FindControl()in the repeaters item databound event to grab the specific ListView in order to set the Data Source, and also to call DataBind on it.You can use the data binding shortcut
<%# ... %>within the nested Repeater / DataList, but not to set the DataSource as you have done.Paste the following into a blank new project. Compiles and runs.
(Big disclaimer – the html is just for demonstration and is pretty poor.)
Web Form Code.
Now in the code behind
Person class is just for demonstration.
Note that in this example I’m grouping using ToLookup to create a grouping from a list. In the real code this is derived from, it’s showing a page of data ordered by what happens on a particular day. E.g. the records are sorted by
thing.SomeDateand the grouping isquery.ToLookup( o => o.SomeDate.ToLongDateString() );It’s important to note that the
ToLookupand use ofIGrouping<T,X>is irrelevant except I need to get grouped data in there somehow for the purposes of example. You could just as easily have the canonical example ofOrderandOrderDetailwhere the outer ListView is aList<Order>and the inner ListView is theOrder.OrderDetails