﻿# Another article in the offing...hopefully...if I get round to it...Member methods versus OnItemDataBound for nested Data List controls

<datetime class="hidden">2004-02-20T00:00</datetime>
<!-- category -- mostlylucidcouk, Imported, ASP.NET, C#, Performance -->

A very common question in the [ASP.NET Forums](http://www.asp.net/forums)is "How do I nest one Repeater (or DataList or DataGrid) inside of another?"; well, my usual stock answer used to be to use the OnItemDataBound event then use a FindControl() to find the Repeater inside the template and set it's datasource to the child view - then just DataBind...Recently though, I've gone against this - based in part on a bit in a book by Farhan Muhammad and Matt Milner (can't find the link to the exact book, but [this one](http://www.amazon.co.uk/exec/obidos/ASIN/1590590724/mostlylucid-21)is pretty useful too), essentially, it involves using a member method. So, instead of hooking up the event you simply specify the DataSource of the Child Repeater as follows (for example)  

&lt;asp:Repeater id=FormatsRepeater DataSource="&lt;%# GetFormats(Container.DataItem)%&gt;" Runat="Server"&gt;

, along with the rest of the templates etc for the child repeater. Then, in code (the codebehind normally), you simply do this: 

public DataView GetFormats(object DataItem)
{
DataRowView di = DataItem as DataRowView;
if(di!=null)
return di.CreateChildView("JobCount");
else
return null;
}

Hmm..[BlogJet](http://blogjet.com/) isn't great at letting me modify HTML - I'll sort this later...anyway, as you can see, very simple code (incidentally, should mention, I'm using a DataSet with a [DataRelation](http://www.dotnetjohn.com/articles.aspx?articleid=63) called JobCount). What's the upshot of all of this...well, the Member Method version, as well as (IMHO) being much easier to write than the ItemDataBound version - is also MUCH faster - in some tests, twice as fast! Anyway, I will hopefully write a bigger piece on this with some stats to prove my point - if I get round to it :-)