Can I have one method that will take either a RepeaterItemEventArgs or DataListItemEventArgs?

A

Alan Silver

Hello,

I am writing the code-behind for a user control that may have either a
Repeater or a DataList (depending on which .ascx file calls the
code-behind). I have put an DataItemBound event for each of these two
controls, and wrapped the DataBind() method in a try/catch block, so if
the .ascx that called the code doesn't have one, the code will still
continue.

All's well so far, but I have some complex code in the DataItemBound
event handler that needs to be the same for both controls. I would like
to move it into a separate method that can be called from either event
handler.

The problem is that the Repeater control gets a RepeaterItemEventArgs
object passed to its event and a DataList gets a DataListItemEventArgs
object. I would like to have a method that can accept either, and deal
with them in exactly the same way.

I thought of declaring the method with a parameter of EventArgs (from
which both other objects are derived), but this didn't work as this
doesn't contain the Item object which is needed.

Anyone any ideas how I handle this? It seems poor coding to have two
identical methods, other than the type of the single parameter passed,
but I can't see how to avoid it.

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,834
Latest member
BuyCannaLabsCBD

Latest Threads

Top