How to pass a parameter to a function that is called on an event?

Pass new parameter to function called in OnItemDataBound event

  • I have a question regarding the OnItemDataBound event and I'm hoping someone can help me out. Right now I have and the function definition is: protected void FillRepeater(object sender, RepeaterItemEventArgs e) What I'd like to do is pass a parameter to the function like this: But I'm not sure this is possible? I've edited my function definition to protected void FillRepeater(object sender, RepeaterItemEventArgs e, int num) but I'm not sure how to edit the markup to pass the first 2 expected parameters?

  • Answer:

    You can't modify the signature of ASP.NET server control event handlers, but I suspect that you're trying to either pass the index of the current item or grab a property off of the current item. Here's a few lines that might help you out if that's your aim: protected void FillRepeater(object sender, RepeaterItemEventArgs e) { // this will get the object that the current repeater item is bound to YourItemType item = e.Item.DataItem as YourItemType; // this will get the index of the current repeater item var collection = repeater.DataSource as List<YourItemType>; int itemIndex = collection.IndexOf(e.Item.DataItem as YourItemType); }

Felipe Kettle at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.