473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Custom Validator checking for dulicates in database from gridview

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.SelectNamedZonesTableAdapte r

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

Feb 22 '07 #1
1 1860
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

"Hawk" wrote:
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.SelectNamedZonesTableAdapte r

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
Feb 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike P | last post by:
Why do the validation server controls behave differently on my live site from on my local development machine? I have several text boxes that are validated by Required Validators and a couple of...
9
by: Alex Shirley | last post by:
Hi there I’m simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
0
by: Khuzema | last post by:
Dear All, I am using issue tracker architecture and developed business object for my application. Now, in VS Beta 2, I humbly want to know how i can have same feature as dataset, in my business...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
2
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User...
4
by: kpg | last post by:
I can't get the CustomValidator (CV) ErrorMessage to display in the ValidationSummary. On the same page I have several RequiredField Validators and a Range Validator, that all work just fine,...
3
by: Rich Squid | last post by:
Hello Here's my basic problem: On my asp.net form page I have a DetailsView (default mode=edit) bound to a AccessDataSource control. Users can successfuly update a databound template field,...
5
by: =?Utf-8?B?R2FyeSBMYXJpbWVy?= | last post by:
Created a Custom Validation Ctrl in EW2 to validate a text box entry. Want to make sure entry is evenly divisible by 7, and that value is not 0. However, args.IsValid = false, even if 77 is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.