Link to home
Start Free TrialLog in
Avatar of Simon Cripps
Simon CrippsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Details view validation

Hi, I am looking to validate a detailsview as I select update.
I will be looking to check for null values, and checking some feild dependant on values on other field.
I have got my start off code attached but did not get far as it did not understand that I was trying to check if the field was blank and also id not recognize that I was trying to cancel the command if this was blank.

Any suggestions or examples you may have, would be most welcome.
Sub CustomerDetailView_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs)
        Select Case e.CommandName
            Case "Cancel"
            Case "Update"
                If DetailsView1.DataItem("VCDescription") = "" Then
                    'cancel this command
                    DetailsView1.DataItem("VCDescription") = "dfgdsf"
                End If
            Case "Insert"
            Case Else
        End Select
    End Sub

Open in new window

Avatar of guru_sami
guru_sami
Flag of United States of America image

Just wondering what is it that you want to Validate? The values in the textboxes right?
In that case you can use Validator controls in the markup itself.
For checking within the event, you can use individual events like:
ItemUpdating and there you do a e.Cancel=true to cancel the event if validation fails.
Avatar of Simon Cripps

ASKER

I'll be doing serveal check on the events.
the 2 bits in here I can't understand are
1) defining the content of the text field
If DetailsView1.DataItem("VCDescription") = "" Then
Does not work
2) Placing  e.Cancel into the code above does not work as I get the responce
cancel is not a member of System.Web.UI.WebControls.DetailsViewCommandEventArgs
If I clear these two I should be able to push on.
Cheers
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your patience, I am now doing it with control values and works well.
Thanks