Could you please give me sample code b/c I'm not seeing how it's deleting from the database and how the panel gets shown.
Thanks.
Main Topics
Browse All TopicsHello,
I have a list of records that is rendered to a page and would like to toggle between panels.
In the last column is a delete buttons. When the user clicks delete, I want the list to go away and bring up another panel that says, "Your record is now deleted."
I just don't know how to do it.
When the user clicks delete, how do I programatically in my code behind delete the record? How do I recognize in my code behind that the delete has been clicked?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is an example of performing various events with the GridView control (http://www.codeproject.co
The displaying of the panel would be to set the Visible property of the panel to true.
Ok. I get the gist. Thanks for the site.
Please see below, how do I get the id from querystring?
protected void GridView1_RowCommand(objec
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
string type;
string trackID;
string medID;
string copy;
trackID = Request.QueryString["track
type = Request.QueryString["type"
medID = Request.QueryString["medID
copy = Request.QueryString["copy"
thx.Text = trackID.ToString();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.Conne
conn.Open();
SqlCommand cmdMed = new SqlCommand("delMediaReques
cmdMed.CommandType = CommandType.StoredProcedur
cmdMed.Parameters.Add(new SqlParameter("@medID", medID));
cmdMed.Parameters.Add(new SqlParameter("@trackId", trackID));
cmdMed.Parameters.Add(new SqlParameter("@copy", copy));
cmdMed.Parameters.Add(new SqlParameter("@type", type));
cmdMed.ExecuteNonQuery();
}
}
Let's take a step back. If you have modified your ButtonField to have the CommandName="Delete" (in the GridView wizard, this is a CommandField of Delete) then you should use the OnRowDeleting event to perform you delete, not the OnRowCommand event. The OnRowDeleting (and OnRowDeleted) uses GridViewDeleteEventArgs that has the property RowIndex. This property tells you the index of the row where the delete button was clicked. (The OnRowCommand event is useful when you have a button that needs to trigger an event that is not Edit, Update, Delete or CancelUpdate, but otherwise is not needed. The OnSelectedIndexChanged event is also not needed unless you've added a button that has a command name of "Select". The OnRowDataBound event is also not needed unless you are performing special processing when a row from your data source is bound to your grid.)
To provide additional assistance, the GridView has the property DataKeyNames, which you can populate with the field names (comma-delimited) from your data source. From your code, this would be: trackId, type, medID, copy. <-- If you have an single column in your data table that uniquely identifies the row, such as an Identity column, then you are better off using that column.
When the GridView is bound to your data source, the GridView populates the DataKeys array with the values from your data source that match the field names you specified in the DataKeyNames property. You can then access this array in your OnRowDeleting function like this:
myRequestGridView1.DataKey
Ok. Thanks. I looked into what you wrote and went online and did a lot of studying at different sites.
I think I'm close but for now, I've hit a ceiling. See my code below:
The error I get is this,
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0123: No overload for 'myRequestGridView1_RowDel
Source Error:
Line 33: <tr>
Line 34: <td class="formFields" colspan="2">
Line 35: <asp:GridView ID="myRequestGridView1" runat="server" <--- Highlighted
Line 36: AutoGenerateColumns="False
Line 37: OnRowDeleted="myRequestGri
The OnRowDeleted event uses the GridViewDeletedEventArgs (notice past tense of Delete) instead of GridViewDeleteEventArgs. (I thought both events used the same EventArg object, but I now I know they don't!)
There is a significant difference to the two events and the EventArg object used by each event. For instance, GridViewDeleteEventArgs provides the index of the row that will be deleted can the ability to cancel the delete operation. GridViewDeletedEventArgs provided properties to notify you how many rows were affected by the delete and if an exception was raised during the delete operation.
So, I'm suggesting the following:
In your ASPX page, change your OnRowDeleted event to OnRowDeleting.
You should change the function name in the ASPX and code behind (from myRequestGridView1_RowDele
In your code behind, instead of using myRequestGridView1.Selecte
Business Accounts
Answer for Membership
by: Shaun_KlinePosted on 2009-10-15 at 09:10:27ID: 25582028
If you add CommandName="Delete" to your ButtonField, the OnRowDeleting and OnRowDeleted method of the GridView will fire. You can use the OnRowDeleting event to actually delete your data row, and the OnRowDeleted event to display your confirmation panel.