Exercise: Deleting rows in gridview and cancelling event

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> ASP.NET webforms - VB  (27 exercises)
Topic ==> Gridview events  (3 exercises)
Level ==> Average difficulty
Course ==> ASP.NET WebForms - VB
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a new website, and add the files in the folder shown above to it.

Amend the frmFilms web page so that it allows you to delete a film.  You'll need to:

  • Configure the data source for the gridview to include Insert, Update and Delete commands
  • Include an additional column displaying a Delete button

Here's a way to display a command button without using a template field:

ASP.NET 4.0 - Visual Basic exercise - Gridview events (image 1)

You can use the CommandField web server control to display standard buttons

Attach code to the Deleting event so that it cancels deletion for any film made on or after the year 2000, and displays an error message in a div tag:

ASP.NET 4.0 - Visual Basic exercise - Gridview events (image 2)

What happens if you try to delete the film 300, made in 2007

Don't forget to set the event argument's Cancel property to True!

Save and close your files.

This page has 0 threads Add post