Conditional Deleting of a GridView row based on field Value in the currrent row being deleted. ASP 2.0 Framework
Posted on 2006-11-14
platform: .NET 2.0 Framework
I have a gridview with the command field that has the Edit and Delete commands in that column. I want to be able to make a conditional statement when the delete command is fired to check a field in the row for the condition
IF value = "Owner" then don't delete, and set a label message box to alert user that Deleting an Owner is not allowed.
So I believe I can use the RowDeleting Event handler to do this, but am not sure. So I need to know the following.
1. How to reference the Templated field name in the RowDeleting Event (Below I have some code I used in the RowDataBound event, I have tried to use this same code in the Event but it doesn't seem to be able to get at the control)
2. What code would I use to bail out of the delete function if that field is = "Owner"
Here is some code I have that
Label lblGetRole = (Label)e.Row.FindControl("lblRole"); // The column is a templated field this is when in non Editing mode.
DropDownList ddlChangeRole = (DropDownList)e.Row.FindControl("DropDownListRole"); //This is the field in the Template, it becomes a dropdownlist
Any help would be appreciated.