Joe
Joe

Reputation:

How to handle onclick event in a listview button?

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

Answers (2)

Canavar
Canavar

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

Matthew Jones
Matthew Jones

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

Related Questions