views:

41

answers:

2

I am trying to implement the deleting method and pass my parameters for the delete operation. I am using 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?

A: 

ID doesn't need a column in the GridView, as long as it is in the datasource. Here's a simple GridView tutorial explaining the procedure...

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

Their RowDeleting handler...

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  customer.Delete(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
  FillCustomerInGrid();
}
kervin
Thanks that solved my problem
George
A: 

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):

<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
    }
kekekela