ASP.NET GridView Button Event

后端 未结 2 1825
天涯浪人
天涯浪人 2020-12-22 08:17

I\'m trying to trigger a button event in a gridview. I created a gridview with the following code:



        
2条回答
  •  眼角桃花
    2020-12-22 08:49

    You should add an OnRowCommand event in the GridView and then implement an event handler. On your Button instead of implementing OnClick you should optionaly just provide the attributes CommandName and CommandArgument i.e:

    
    

    Then in your OnRowCommand event handler you can add your code

    string test = "test";
    

    The click of the Button will always trigger the OnItemCommand event, even if you do not specify the CommandName attribute, however this allows you to have multiple buttons on a row, so that each one will perform a different functionallity. The CommandArgument allows you to provide an argument for your functionallity. If for example you wanted to pass the ID of the Person you are seeing, you could pass CommandArgument="<%# Eval("PersonID") %>

提交回复
热议问题