How to create a delete button in GridView?

前端 未结 4 649
爱一瞬间的悲伤
爱一瞬间的悲伤 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.

    <asp:GridView DataKeyNames="UserName" ID="GridView1" 
         runat="server" OnRowDeleting="GridView1_RowDeleting">
    

    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); 
    }
    
    0 讨论(0)
  • 2021-01-18 04:21

    Here is a great article about typical usages of DataGrid.

    Enjoy.

    0 讨论(0)
  • 2021-01-18 04:34

    1:-

    protected void grdLst_RowDeleting(object sender, GridViewDeleteEventArgs e)
    
    {
    
        int i = Convert.ToInt32(grdLst.DataKeys[e.RowIndex].Value);
        ob.DeleteCoverage(i);
        Response.Redirect("fullcoverage.aspx");
    }
    

    2:-

        GridViewRow row = (GridViewRow)grdlist.Rows[e.RowIndex];
        string name = row.Cells[1].Text;
        Response.Write(name.Trim());
    
    0 讨论(0)
  • 2021-01-18 04:36
    tablename.Rows.RemoveAt(datagrid1.currentcell.rowindex);
    
    0 讨论(0)
提交回复
热议问题