Skip to content

About DataGridView...

yusuf

Asked Mar 11, 2008, 4:04 PM EDT1 answer
Share
LinkedInX

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...

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • paiha paiga
    0

    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

    C#
     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);
    }
    }
    0