Hi everyone...
I m trying to delete data in database by selecting the row from dataGridView. It is deleted from datatable with the code below :
dt.Rows[dataGridView1.CurrentRow.Index].Delete();
i typed dataAdapter.Update(dt); but did not effect the database.
Thank you...
paiha paigaPosted Mar 12, 2008, 1:29 AM
Hi!
you can delete the data from database by selecting the row of the grid view in two way ,First is by calling the RowDeleting event but for this event you would have to mention the DataKeyNames of the GridView that will be the ID of the database from which you have to delete the row.Like as below
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string Id = GridView.DataKeys[e.RowIndex].Value.ToString();
functiondelete(Id);
}
second way is by calling the RowCommand for this no need to mention the DataKeyNames of the GridView..this will be as below
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e){
if (e.CommandName == "Delete"){
string Id = e.CommandArgument.ToString();functiondelete(Id);
}
}