Wednesday, March 28, 2012

Validate item on insert in DetailsView

Hi. Is there a way to validate a value that's being inserted from a DetailsView? We've got the event handler for the "on inserting", but not sure how to grab the column value and validate it. How do you display an error on that item to let the user know to change it? Thank you.

Option 1) You could turn item into a template field and add validation controls.

Option 2) In your Item_Inserting Function you can capture bound fields as follows. This code would stop a blank field in row 1 from being inserted.

ProtectedSub DetailsView1_ItemInserting(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.DetailsViewInsertEventArgs)Handles DetailsView1.ItemInserting If e.Values(0).ToString =NothingThen 'Change the 0 to the row you want to capture 'Display Error Message

e.Cancel =

True'This cancels the insert EndIfEndSub
Thanks, getdotnethelp. That worked like a charmBig Smile

No comments:

Post a Comment