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
--
Alan Silver
(anything added below this line is nothing to do with me)