ng ctee

ng ctee

  • NA
  • 1
  • 1.3k

Delete Function

Jul 17 2012 9:57 PM

Hi all,

I have a gridview on my page and a delete function in the gridview. The WorkID in table Work is the foreign key for table Employee.

Before delete, i need system help me to check whether the WorkID exist in other table or not. If WorkID exist in other table, it will not allow user to delete it. Can anyone guide me with this.

The code i show below is only able to delete those row/data with no foreign key in other table.

protected void gvWork_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
   
{
       
     
     
       
if (e.Row.RowType == DataControlRowType.DataRow)
       
{
           
//Loop all data rows
           
foreach (DataControlFieldCell cell in e.Row.Cells)
           
{
               
//Check all cells in one row
               
foreach (Control control in cell.Controls)
               
{
                   
LinkButton button = control as LinkButton;
                   

                   
if (button != null && button.CommandName == "Delete")
                   
{
                       
// Add delete confirmation
                        button
.Attributes.Add("onclick", "javascript:return " + "confirm('Do you want to delete the record " + DataBinder.Eval(e.Row.DataItem, "WorkName") + "?')");
                   
}
               
}
           
}
       
}
   
}


Answers (2)