Custom Validator checking for dulicates in database from gridview

G

Guest

Hello,
I have been trying to get a duplicate field checker to work within my
gridview using a custom validator. However with the code I have I am getting
an error

error: Object reference not set to an instance of an object

here is my code:


Protected Sub CustomValidator1_ServerValidate1(ByVal source As Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)

' this code is to check for dulicates

Dim result As New Object
Dim result1 As New Object

result = CType(gvAssignedZones.FindControl("TextBox3"), TextBox).Text

If args.Value = result Then
args.IsValid = True
Else
Dim db As New SchedulesTableAdapters.SelectNamedZonesTableAdapter

result1 = db.SelectDupZone(args.Value)

If Not IsNothing(result) Then
args.IsValid = False
Else
args.IsValid = True
End If
End If
End Sub

where I get the error is on this line

result = CType(gvAssignedZones.FindControl("Label3"), Label).Text

What I am trying to do is fisrt check to see if the text in the edit mode is
the same as the text in the item template that way the database check will
not happen and should go straight to update.

If the text is different I want to make the database call and check to see
if there is a result. If so then the update should not accur and the error
message will show instead. other wise the update takes place.

I have this kind of code working for none gridview updates. It seems to get
a bit tricky with this control "gridview" and assigning / finding the correct
values.

Any help or insite would be great.

P.S. I am using strongly typed datasets.

Thanks,
Hawk
 
G

Guest

Just a note

I made a typo on this line: If Not IsNothing(result) Then

the correct code is: If Not IsNothing(result1) Then

Thanks Hawk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top