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
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