title: ItemCommand on nested Repeater
body: <p>I have a simple aspx page which contains 2 nested repeaters.  Each of these have buttons on them.  When the user clicks on a button on the outer repeater, I can capture the ItemCommand in my codebehind, however when the user clicks on an inner one, I cannot capture it.</p>
  
  <p>I have read in other threads about needing to attach the event manually to the inner repeater, but cannot work this out.</p>
  
  <p>Can anyone help?</p>
  
  <p>Here is the aspx.  I'm using vb.net code behind</p>
  
  <pre><code>&lt;asp:Repeater runat="server" ID="ParentRepeater"&gt;
     &lt;ItemTemplate&gt;
          &lt;li id="P&lt;%#DataBinder.Eval(Container, "DataItem.id")%&gt;"&gt;
              &lt;%#DataBinder.Eval(Container, "DataItem.name")%&gt;
              &lt;asp:Button runat="server" ID="adedit" Text="Edit" CommandName='&lt;%#DataBinder.Eval(Container, "DataItem.id")%&gt;'
                  class="pages-edit" /&gt;
              &lt;asp:Button runat="server" ID="addel" Text="Delete" CommandName='&lt;%#DataBinder.Eval(Container, "DataItem.xid")%&gt;'
                  class="pages-delete" /&gt;
              &lt;ul class="page-section sub innerdrag"&gt;
                  &lt;asp:Repeater runat="server" ID="childrepeater"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;li id="&lt;%#DataBinder.Eval(Container, "DataItem.id")%&gt;,"&gt;
                              &lt;%#DataBinder.Eval(Container, "DataItem.name")%&gt;&lt;asp:Button runat="server" ID="ad_edit"
                                  Text="Edit" CommandName='&lt;%#DataBinder.Eval(Container, "DataItem.id")%&gt;' class="pages-edit" /&gt;
                              &lt;asp:Button runat="server" ID="ad_del" Text="Delete" CommandName='&lt;%#DataBinder.Eval(Container, "DataItem.xid")%&gt;'
                                  class="pages-delete" /&gt;
                          &lt;/li&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:Repeater&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Still not firing so I've put the updated VB here too</p>
  
  <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          If Not IsPostBack Then
              Dim DBFunctions As New DBFunctions.Functions
              Dim dstmp As New DataSet
              Dim dstmp2 As New DataSet
              dstmp = DBFunctions.SQLDataSet("SELECT id,name, 'x'+cast(id as varchar(50)) as xid from pages where parent = 0 and coalesce(active,1)=1 order by orderby asc", "data")
              dstmp2 = DBFunctions.SQLDataSet("SELECT id,name , 'x'+cast(id as varchar(50)) as xid,parent from pages where parent &gt;0 and coalesce(active,1)=1 order by orderby asc", "data2")
              Dim allData As New DataSet
              allData.Tables.Add(dstmp.Tables(0).Copy)
              allData.Tables.Add(dstmp2.Tables(0).Copy)
              allData.Relations.Add(New DataRelation("Children", allData.Tables(0).Columns("ID"), allData.Tables(1).Columns("parent")))
              ParentRepeater.DataSource = allData
              ParentRepeater.DataBind()
              sdhfunctions.Close()
          End If
      End Sub
  
      Protected Sub repMenu1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles ParentRepeater.ItemDataBound
          Dim dv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
          If dv IsNot Nothing Then
              Dim repSubMenu As Repeater = TryCast(e.Item.FindControl("childrepeater"), Repeater)
              If repSubMenu IsNot Nothing Then
                  AddHandler repSubMenu.ItemCommand, AddressOf childrepeater_ItemCommand
                  repSubMenu.DataSource = dv.CreateChildView("Children")
                  repSubMenu.DataBind()
              End If
          End If
  
      End Sub
      Protected Sub ParentRepeater_ItemCreated(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles ParentRepeater.ItemCreated
          Dim dv As DataRowView = TryCast(e.Item.DataItem, DataRowView)
          If dv IsNot Nothing Then
              Dim repSubMenu As Repeater = TryCast(e.Item.FindControl("childrepeater"), Repeater)
              If repSubMenu IsNot Nothing Then
                  AddHandler repSubMenu.ItemCommand, AddressOf childrepeater_ItemCommand
                  repSubMenu.DataSource = dv.CreateChildView("Children")
                  repSubMenu.DataBind()
              End If
          End If
  
      End Sub
  
      Protected Sub childrepeater_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
          Dim stophere As String = ""
      End Sub
  </code></pre>
  
  <p>I put a breakpoint on stophere, and it never gets hit.</p>
  
  <p>Sorry guys, I'm really confused :(</p>