Hi,
I assume that your webform has a datagrid wherein each row has a radiobuttonlist with two options and a textbox. and there is submit button. When this button is clicked, the validation has to be performed.
When u hit the submit button, if one of the options in the radiobutton list is selected, the textbox shud not be empty.
U dont even have to use a custom validator. Because a custom validator only validates a particular control. In the validation function, if u only want to check a particular button is selected, u can do that if the controltovalidate of the validator is set to the radiobuttonlist. But in this function you cant get the textbox value because there is no reference to that particular item in the datagrid.
U can do the validation as follows on the submit button click (or whatever event in ur code)
Dim dgi As DataGridItem
For Each dgi In DataGrid1.Items
If CType(dgi.FindControl("RadioButtonList1"), RadioButtonList).SelectedItem.Value = "1" And CType(dgi.FindControl("TextBox1"), TextBox).Text = String.Empty Then
ErrorMessageLabel.text = "The textbox cannot be empty if Option 1 is selected"
Exit Sub
Else
ErrorMessageLabel.text = String.Empty
'Do the remaining tasks
End If
Next
Thanks
Pradeepa
|