Mike,
What you're doing now, with the ItemCommand event and the switch block, is
the clean way to do it.
Since you can't predict how many link buttons there are going to be, it
would be hard to do what you're talking about. You'd have to declare each
button using the UniqueID and row number in the same way the repeater
generates the IDs for the buttons, and then add the event handler to each
button. To try to make that all work out would be a lot of work.
The other option is to create your own repeater control derived from the
System.Web.UI.WebControls.Repeater and handle the event handler assignments
in your override of the OnItemCreated or OnItemDataBound events or you could
create your own custom template implementing the ITemplate interface.
All told, I would stick with the ItemCommand event and switch block.
Dale
"mikelor" <> wrote in message
news:cd8u61$...
> Hi,
> I have a repeater control with more than one LinkButton. I know I can
> use the ItemCommand event handler for the repeater control to catch the
> LinkButton Command events as long as I give each LinkButton a unique
> command name I can do something like this
>
> private void MyRepeater_ItemCommand( Object o, RepeaterEventArgs e )
> {
> switch( e.CommandName )
> {
> case "Edit":
> DoEdit();
>
> case "Delete"
> DoDelete();
> }
> }
>
> However what I would like to do is have a event handler for each
> LinkButton Command Event
>
> private void EditLinkButton_Command( Object o, CommandEventArgs e )
> {
> DoEdit();
> }
>
> private void DeleteLinkButton_Command( Object o, CommandEventArgs e )
> {
> DoDelete();
> }
>
> The second way seems a bit cleaner to me. However when I try and add
> the event handler I get a null reference exception on the
> editLinkButton object
>
> this.editLinkButton.Command += new CommandEventHandler(
> this.EditLinkButton_Command )
>
> Even though I have
> <asp:LinkButton id="editLinkButton" ...>Edit</asp> in my repeater and
> have delclared
>
> protected LinkButton editLinkButton;
>
> in my codebehind.
>
> Like I said, I can get it to work using the ItemCommand event handler,
> but it seems a bit messy to me to use the switch case to determin the
> object sending the event. However all code that I've searched for seems
> to do it this way..
>
> Any other ideas?
> -=mike
>
|