Adding an Event Handler via Code



var list = SPContext.Current.Web.TryGetList("ListURL");
if(list!=null)
{
    SPEventReceiverDefinition eventHandler = list.EventReceivers.Add();
    eventHandler.Assembly = AssemblyName;
    eventHandler.Class = ClassName;
    eventHandler.Name = Name;
    eventHandler.SequenceNumber = 11111;
    eventHandler.Synchronization = SPEventReceiverSynchronization.Synchronous;
    eventHandler.Type = SPEventReceiverType.ItemUpdating;
    eventHandler.Update();
}

Adding an event handler declaratively in a list definition.



    <ListTemplate
           Name="List"
           DisallowContentTypes="FALSE"
           Type="11111"
           BaseType="0"
           OnQuickLaunch="TRUE"
           SecurityBits="11"
           Sequence="410"
           DisplayName="SharepointList"
           Description="Custom list"
           Image="/_layouts/images/itgen.png"/>
      
    <Receivers ListTemplateId="11111">
        <Receiver>
            <Name>ListItemReceiverItemAdding</Name>
            <Type>ItemAdding</Type>
            <Assembly>Custom.EventReceivers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2874d76e87bf204d</Assembly>
            <Class>Custom.EventReceivers.ListItemReceiver</Class>
            <SequenceNumber>11111</SequenceNumber>
            <Synchronization>Synchronous</Synchronization>
        </Receiver>
    </Receivers>
</Elements>