views:

1739

answers:

1

Hi All,

I'm using the FormView control in ASP.NET for a simple form to insert into a MS SQL DB. I have an event for onItemInserting to set some values behind (such as time stamp, etc) and was curious how to check some user entered values in the onItemInserting event and cancel the item from being inserted. The reason I want to do it in the code behind is to query the database and use the values to validate the user entered data.

Pseudo Code is as follows:

protected void Form_addRoom_ItemInserting(object sender, FormViewInsertEventArgs e)

{

... Query DB for some values ...

if(enteredMaxPeople > queryMaxPeople)

{

**Cancel** DB Insert

statusLabel.text = "Value entered not valid";

}

}

In the end the question comes down to how do I cancel a FormView from inserting in the code behind?

Thank you! Sean

+5  A: 
e.Cancel = true;
Steven A. Lowe