I’m working on an application which list movies from a database. Except for general information (title, year etc) I list genres (one dropdown list per genre, which the user can choose genre from).
The thing is that I don’t want the user to be able to delete a genre if only one exists (ie. a move should always have at least one genre), and here’s where I need some help.
In the datasource I’ve created an event for Deleting, where I hope I could accomplish what I want. So, my idea is to find out if it only exists one dropdown list (ie. one genre), and if so, stop the event (deletion) from happening.
I would really appreciate some help here. Thanks in advance!
protected void MovieGenreDataSource_Deleting(object sender, ObjectDataSourceMethodEventArgs e) {
DropDownList ddl = FindControl("GenreDropDownList") as DropDownList;
if (// Number of genres = 1) {
e.Cancel = true;
}
}
Here’s a screenshot from my app (in swedish), where “Redigera” = edit, “Ta bort” = Delete and “Lägg till” = “Add”. I hope it makes my problem more clear.

Is this what you need?