The last step is to add the code to the Delete button's click
event to delete a record.
1.
Switch back to Design view and double click on the Delete button to
generate the click event handler.
2.
Add the following code.
if (ddlUsers.SelectedItem.Value != "")
{
ArrayList validationErrors = new ArrayList();
UserAccountEO userAccount = new UserAccountEO();
userAccount.Id = Convert.ToInt32(ddlUsers.SelectedValue);
userAccount.Delete(ref validationErrors);
if (validationErrors.Count > 0)
{
ShowValidationMessages(validationErrors);
}
else
{
LoadUserDropDownList();
txtFirstName.Text = "";
txtLastName.Text = "";
lblInserted.Text = "";
lblUpdated.Text = "";
lblErrorLabel.Visible = false;
lblErrorMessages.Visible = false;
}
}
This code creates an instance of a UserAccountEO object and
sets its Id property to the value selected in the drop down list. It then
calls the Delete method. Once the record is deleted the drop down list is
reloaded so the user is removed and the textboxes and labels are cleared.