G
Guest
Hello,
I have the need to verifiy a field in a gridview for a duplicate value
against a database before the update takes place. I was thinking that the
gridview1.rowupdating would be a good place to put code that can check for
duplicate data before the update happens.
Below is a sample of the code i was trying but did not work.
Protected Sub gvAssignedZones_RowUpdating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
gvAssignedZones.RowUpdating
'add a dup check for zones name before updateing.
Dim db As New
HydroClass.SchedulesTableAdapters.SelectNamedZonesTableAdapter
Dim result As Object =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"), TextBox).Text)
Dim lb As New Label
lb.Text =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"),
TextBox).Text).ToString
If Not lb.Text =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"),
TextBox).Text).ToString Then
If Not IsNothing(result) Then
gvAssignedZones.EditIndex = 0
Else
odsGVAssingedZones.Update()
End If
End If
End Sub
SO the idea here was to call an other tableadapter and add the value from
the correct field in the gridview and if the result was true or not nothing
then the gridview would stay in edit mode and if not the update from the
objectdatasource would kick in.
Yes I would also add an error message later this is just to test it first.
The idea of the Label was to see if the text was the same before updating
that way the duplicate check would be skipped in order to prevent errors.
Thank you,
Hawk
I have the need to verifiy a field in a gridview for a duplicate value
against a database before the update takes place. I was thinking that the
gridview1.rowupdating would be a good place to put code that can check for
duplicate data before the update happens.
Below is a sample of the code i was trying but did not work.
Protected Sub gvAssignedZones_RowUpdating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
gvAssignedZones.RowUpdating
'add a dup check for zones name before updateing.
Dim db As New
HydroClass.SchedulesTableAdapters.SelectNamedZonesTableAdapter
Dim result As Object =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"), TextBox).Text)
Dim lb As New Label
lb.Text =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"),
TextBox).Text).ToString
If Not lb.Text =
db.SelectDupZone(CType(gvAssignedZones.FindControl("TextBox3"),
TextBox).Text).ToString Then
If Not IsNothing(result) Then
gvAssignedZones.EditIndex = 0
Else
odsGVAssingedZones.Update()
End If
End If
End Sub
SO the idea here was to call an other tableadapter and add the value from
the correct field in the gridview and if the result was true or not nothing
then the gridview would stay in edit mode and if not the update from the
objectdatasource would kick in.
Yes I would also add an error message later this is just to test it first.
The idea of the Label was to see if the text was the same before updating
that way the duplicate check would be skipped in order to prevent errors.
Thank you,
Hawk