0

How do I add an Event Receiver to two lists?

One must be updated when an Item is inserted in a second list.

I used public override void ItemAdding(SPItemEventProperties properties)

But what should i put in this method ?

1 Answer 1

1

Grzegorz,

What happens with Event Receivers, in the receiver in feature XML has a ListTemplateId which determines to which List template the event receiver is for... So lets say you need to add event receiver on custom list then ListTemplateId=100 or you want to add to Announcements template the ListTemplateId=104, like below:

`<Receivers ListTemplateId="100">`

Now if you attach event receiver to custom list template, the event will fire for every custom list you have in the scope! And you can identify the list in code by using properties... the SPItemEventProperties has a property called List.. which give you SPList, and you can either by GUID or Name identify the list and perform operation accordingly... What I do is create a SWITCH-CASE for different lists and perform operations according in the cases!

I hope this answered and clarify the concept of Event Receivers, you can read more over here and here

So when you have deployed the event receiver it will fire for both the lists, and you will first identify for which list it has been fired.. then code accordingly!

10
  • Thanks for replay :) But how tu choose one list too add another list?
    – Grzegorz Z
    Oct 15, 2012 at 9:32
  • I cant understand this: "the SPItemEventProperties has a property called List.. which give you SPList,", how I can do It ?
    – Grzegorz Z
    Oct 15, 2012 at 9:43
  • I wont only add one list to another
    – Grzegorz Z
    Oct 15, 2012 at 9:48
  • You have this public override void ItemAdding(SPItemEventProperties properties) right? If you write properties.List you have the list for which the event receiver is called Oct 15, 2012 at 9:48
  • sorry, what you mean by "actualizing when in the secound element add's" or "I wont only add one list to another" ? Oct 15, 2012 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.