简体   繁体   English

在GridView上删除行方法

[英]Deleting Row Method on GridView

I am trying to implement the deleting method and pass my parameters for the delete operation. 我正在尝试实现delete方法,并将我的参数传递给delete操作。 I am using sqldatasource. 我正在使用sqldatasource。 Since the ID doesnt have a column in my gridview how can I get the value of the ID and set it as my delete parameter? 由于ID在我的gridview中没有一列,如何获取ID的值并将其设置为我的delete参数?

ID doesn't need a column in the GridView, as long as it is in the datasource. ID不需要在GridView中的列,只要它在数据源中即可。 Here's a simple GridView tutorial explaining the procedure... 这是一个简单的GridView教程,介绍了该过程...

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx

Their RowDeleting handler... 他们的RowDeleting处理程序...

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  customer.Delete(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
  FillCustomerInGrid();
}

You can set up a method to handle the gridview's OnRowDeleting event, cancel the delete there, and implement your own logic to perform the delete (ie delete based on some field besides id): 您可以设置一个方法来处理gridview的OnRowDeleting事件,在那里取消删除,并实现自己的逻辑来执行删除(即,基于id之外的某些字段的删除):

<asp:GridView OnRowDeleting="gridview_rowdeleting" />


protected void gridview_rowdeleting(Object sender, GridViewDeleteEventArgs e)
    {
    e.Cancel = true;
        // logic for performing delete here...e.Rows returns the collection of deleted rows so you can access whatever values you need...e.Rows[0].Cells[0] gives the value in the first column for the first deleted row for example
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM