handle button click event inside gridview

2019-09-11 03:18发布

问题:

I am writing asp.net project in C#.

The page consists of gridview, it is filled from database initially. The buttons, textboxes and dropdownlists are inside gridview as in the picture picture.

I want to handle button(сообщить) click event so that I know what row of gridview is clicked in order to get the selected value of dropdowlnist and value of textbox from that row to update the database.

Does someone know how to do this? Thanks!

回答1:

My first thought is that if you are using the <asp:TemplateField> tags inside your gridview page, then you should be able to register an event in your button code as such: <asp:Button runat="server" OnClick="MyOnClickEvent" />. If you are programmatically adding them, you should be able to use the onClientClick property of the button.

Try reading http://www.codeproject.com/Articles/50540/GridView-Event-Handling. It might point you in the right direction.



回答2:

you can try e.RowIndex on the event of the btnсообщить_Click



回答3:

You can handle the click event of any button type control inside gridview in two ways. The first is through event bubbling, and the second one is directly (in this type of event handling we need to access current girdviewrow container).

I think you should take a look at this article for further knowledge.

How to handle click event of linkbutton inside gridview