How to create a delete button in GridView?

前端 未结 4 654
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 03:38

I made another Column in my GridView called delete. When delete is clicked, the row should be deleted or in other words, I need to get the current row\'s user n

4条回答
  •  遥遥无期
    2021-01-18 04:20

    You can use the RowDeleting event, by storing the user name in the data key collection you can access it programmatically.

    
    

    Then, in the code behind use the data key to delete the record.

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
      string userName = (string) GridView1.DataKeys[e.RowIndex].Value;
      DeleteUser(userName); 
    }
    

提交回复
热议问题