How to handle onclick event in listview button?

If I have a listview control using a button in an element template, how do I handle onclick events for each of the buttons that end up getting in the list?

+4
source share
2 answers

You can use the CommandArgument property of a button control to indicate which button is clicked.

This example shows how to get values ​​from a command argument in a listview control.

+4
source

The same thing 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 pressed in the handler itself.

 protected void templateButton_OnClick(object sender, EventArgs e) { Button myButton = (Button)sender; } 
0
source

Source: https://habr.com/ru/post/1286717/


All Articles