protected void gvMyRecord_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlCommand command = new SqlCommand("DELETE FROM customer_record WHERE customer_id='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'");
connection.Open();
command.ExecuteNonQuery();
connection.Close
FillVendorGrid();
}
QUESTION: i an unable to understand this code please give me some guideline i will be very thank full to you
Sunny SharmaPosted Aug 2, 2013, 5:42 AM
Iftikar HussainPosted Aug 2, 2013, 5:36 AM
Iftikar
Regards,
Iftikar
Sunny SharmaPosted Aug 2, 2013, 5:33 AM
RowDeleting event fires just before the row gets deleted inside a gridview in asp.net. To answer your question that this Delete event is not working- you must have a command button or link that will invoke this event.
As you're unable to understand this code, let me explain a bit. Two events are fired when deleting a record in gridveiw, the first one is RowDeleting and the other is RowDeleted.
When you invoke a delete command on your gridview it first fires the RowDeleting event offering you the chance to update your database for the record being deleted. until this event completes, your data remain in gridview, it's not deleted yet. After RowDeleting it fires RowDeleted which allows you to update any related view/control on the page if connected to the gridview.
Hope you got the point and find it useful.
Happy Coding :)
muhammad waqasPosted Aug 2, 2013, 5:28 AM
Iftikar HussainPosted Aug 2, 2013, 5:16 AM
The RowDeleting event is raised when a row's Delete button is clicked
try like this
string id=ResultGridView.DataKeys[e.RowIndex].Value.ToString();
Regards,
Iftikar
Posted Aug 2, 2013, 5:14 AM
It will get the ID or primary key values from the ResultGridView.DataKeys[e.RowIndex control.
Later the ID will get passed into the Delete statement and command + connect object will execute the query.
BTW,
Are you getting any exception?
What is the result of command.ExecuteNonQuery()?