views:

41

answers:

4

I have a FormView through which I set up the default new, update and delete commands for communicating with an SQL Server database.

When the CREATE command is executed the data is added to the database and some images are uploaded to a server and linked to the database.

Problem

When I press the Visual Studio's default FormView DELETE command I obviously only delete the selected row in the database and not the images on the server.

I marked the uploaded images with images ID + "name" , so I could delete them if I could only retrieve the ID of the row being deleted by the DELETE command.

How do I do retrieve the ID of the deleted row in C#?

A: 

Handle the SqlDataSource's Deleting event.

SLaks
+1  A: 

Probably the best solution would be to rework the design of your database a little bit and use a foreign key on your images. You could then set the images to be deleted by the database when the primary key (your data table) is deleted using a cascade.

Alternatively, assuming you cannot change your database schema, you can use the ItemCommand event from the FormView. This will let you intercept the commands as they're being processed; you can also handle the ItemDeleting or ItemDeleted events.

Coding Gorilla
As I understand, the images aren't in the database
SLaks
yes the images aren't in the database, i'm going to try the handleing ItemCommand event... from the example i think that'll work..THANKS!
Andrej
A: 

thanks for the anwsers, I thought Coding Gorilla would do the trick.. maybe it does, but here's the thing.. I know how to perform an action onDeleteComandClick, BUT i don't know how to get the ID (or any other data from the database) from the current opened dataitem in formview... any ideas? btw: i'm working with winforms

Andrej
A: 

hm... i didn't know FormView.SelectedValue gets the id of the selected value from the formview, but as I tested now.. apparently it does...

Andrej