When you have controls nested inside a databound control, you have two options to hook up their events to event handlers.
One option is to handle the 'OnItemDataBound'/'OnRowDataBound' or equivalent event of the parent control, find the child control and then use 'AddHandler' to hook up the event handler.
The second option is to declaratively put the name of the event handler sub in the markup of the child control and have 'AutoEventWireup' do the mapping for you.
With some of the built in ASP.NET controls, you will see the events available to you in the Intellisense dropdown. For example, when nesting a repeater you will see 'OnItemDataBound', 'OnDisposed', 'OnInit' etc.
When you have a UserControl inside the databound control you may have declared some custom events but none of these will appear in Intellisense. However, ASP.NET will apply the same rules when it comes to wiring up your events.
All you need to do, is set an attribute on your custom control (in the markup) which consists of 'On' and the event name. ASP.NET will recognise the 'On' prefix, marry it up with the existing event declaration in the UserControl and will treat the value part of the attribute declaration as a named public/protected sub in the current context (i.e. the codebehind for the code infront you are working with).
To exemplify this idea, the following shows a basic implementation:
Partial Public Class ExampleUserControl
Public Event ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
Private Sub btnCompare_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClickMe.Click
RaiseEvent ButtonClick(Me, EventArgs.Empty)
<%@ Register src="/UserControls/ExampleUserControl.ascx" tagname="ExampleUserControl" tagprefix="MyCtrls" %>
<asp:Repeater ID="rptExample" runat="server">
<MyCtrls:ExampleUserControl ID="ExampleUserControl1" runat="server" OnButtonClick="ButtonClickHandler"></MyCtrls:ExampleUserControl>
Protected Sub ButtonClickHandler(ByVal sender As Object, ByVal e As EventArgs)
'handle the user control event
Of course, you need to have 'AutoEventWireup=True' in the web.config or @Page directive for this to work.