Groups | Blog | Home
all groups > asp.net webcontrols > november 2007 >

asp.net webcontrols : Gridview error handling


Arne Garvander
11/12/2007 2:37:00 PM
I have a gridview control that is updateable. One of the data elements is
date, which is very easy to misstype. An invalid date will throw an error. Is
there a way to handle that error in a neat and clean manner?
--
Arne Garvander
Certified Geek
Manish Bafna
11/12/2007 10:04:00 PM
Hi,
Try placing necessary validator controls in the edit template
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
Arne Garvander
11/13/2007 7:56:00 AM
Thanks for the tip.
I can get the validator to validate a date, but if I add time to the date,
the validator will missfire.
In a regular form I can validate a date+time, but not in a gridview template.

--
Arne Garvander
Certified Geek
Professional Data Dude


[quoted text, click to view]
Phil H
11/17/2007 8:34:43 AM
On 13 Nov, 15:56, Arne Garvander
[quoted text, click to view]

The alternative is to place validation code in the
GridView.RowUpdating event. There you can use DateTime parsing and any
other checks you wish to make. If the validation fails then the event
argument e (GridViewUpdateEventArgs.Cancel) can be used to abort the
update and return the grid to the edit view (using label controls for
error messages).

Arne Garvander
11/19/2007 6:18:02 AM
That doesn't work.
--
Arne Garvander
Certified Geek
Professional Data Dude


[quoted text, click to view]
slam radio
11/21/2007 11:56:05 AM
Try this, it works! :)

Private Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvSchedule.RowUpdated
If e.Exception IsNot Nothing Then
ErrorMessageLabel.Text = e.Exception.Message
e.ExceptionHandled = True
e.KeepInEditMode = True
End If
End Sub

EggHeadCafe - .NET Developer Portal of Choice
AddThis Social Bookmark Button