Reputation:
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?
Upvotes: 4
Views: 17559
Reputation: 48088
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.
Upvotes: 4
Reputation: 26190
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;
}
Upvotes: 0