Hello,
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:
me.RequiredFieldValidator1.ControlToValidate="txt1"
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
RFV.Validate()
If Me.IsValid Then
UpdateDatasetFromGrid()
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.
Thanks
Rejo