troubleshooting Question

How to perform validation in an editable datagrid

Avatar of bcombe
bcombe asked on
.NET ProgrammingASP.NET
9 Comments1 Solution203 ViewsLast Modified:
I am using visual studio 2003 with framework 1.1.  And a regular buit-in datagrid server control

I have an editable datagrid with the following structure  (3 columns)

colmun0=title   colmun1=value   colmun2=edit-button

When the user clicks the edit button the column 1 becomes a text box and they can edit the value by clicking the update button.  This mechanism works just fine however :

The problem that I am having is that I don't know how to validate the data that is entered.

My first approach was to drop a requirefieldvalidator control and try to assign the controlToValidate property programmatically when they click the update button

like this:

I was hopping that the  single control  RequiredFieldValidator1 could handle the validation of all the text boxes in the grid because the statment me.RequiredFieldValidator1.ControlToValidate="txt1" will be inside the update_click method. So dynamically it will know what control to validate.

Needless to say that is not working something is missing.

The second approach that I use was to create create the validator programatically in the update_click handler such as this:

  Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand

        Dim RFV As New RequiredFieldValidator

        RFV.ControlToValidate = CType(e.Item.FindControl("txt1"), TextBox).ID


        If Me.IsValid Then
            Me.DataGrid1.EditItemIndex = -1

        End If

    End Sub

This is not working neither.

Can anybody knows how to accomplish this validation?  Some fields are require some fields are telephone or zips , some are dates.


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros