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.



Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 9 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 9 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004