views:

1994

answers:

2

If I have listview control with a button in the item template, how do I handle the onclick events for each of the buttons that ends up getting generated in the listview?

+1  A: 

Same way you do with every other button:

<asp:Button ID="templateButton" runat="server" OnClick="templateButton_OnClick"/>

Except that you will need to determine which button was clicked in the handler itself.

protected void templateButton_OnClick(object sender, EventArgs e)
{
    Button myButton = (Button)sender;
}
Matthew Jones
A: 

You can use CommandArgument property of the button control to specify which button clicked.

This example shows how to get values from command argument within listview control.

Canavar