handle button click event inside gridview

Deadly 提交于 2019-12-13 21:24:59

问题


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



来源:https://stackoverflow.com/questions/11449958/handle-button-click-event-inside-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!