I am using VS 2005.
I have a FileUpload field, textbox, and a gridview.
I have a ValidationSummary.
I have two RequiredFieldValidators for the FileUpload and textbox, they work properly on the client side if the fields are not populated.
I created a CustomValidator for the Gridview, I get the red * to show up beside the Gridview, but I am not sure how to get the ValidationSummary to pop up showing that at least one checkbox needs to be checked in the Gridview.
Here is my code
Code behind:
My CVGridView1_ServerValidate sets args.IsValid to False if no checkboxes are checked in my Gridview, so I know it is processing the value correctly if no checkboxes are selected.
I am not sure how to display a message in the ValidationSummary if results are processed on server side?
Is there a way on client side to check to see if at least one checkbox has been selected?
I have a FileUpload field, textbox, and a gridview.
I have a ValidationSummary.
I have two RequiredFieldValidators for the FileUpload and textbox, they work properly on the client side if the fields are not populated.
I created a CustomValidator for the Gridview, I get the red * to show up beside the Gridview, but I am not sure how to get the ValidationSummary to pop up showing that at least one checkbox needs to be checked in the Gridview.
Here is my code
Code:
<asp:GridView ID="GridView1" ...
<asp:CustomValidator ID="CVGridView1"
OnServerValidate="CVGridView1_ServerValidate"
EnableClientScript="false"
SetFocusOnError="true"
Text="*"
runat="server"
ErrorMessage="Distribution Type must be selected" />
<asp:ValidationSummary ID="ValidationSummary1"
ShowMessageBox="true"
ShowSummary="false"
HeaderText="You must enter a value in the following fields:"
EnableClientScript="true"
runat="server"/>
Code behind:
Code:
Public Sub CVGridView1_ServerValidate(ByVal source As Object, _
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
'Loop through grid looking for a checked checkbox
Dim bFlag As Boolean = False
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim chk As CheckBox = CType(GridView1.Rows(i).Cells(0).FindControl("chkSelect"), CheckBox)
If chk IsNot Nothing AndAlso chk.Checked Then
bFlag = True
End If
Next
args.IsValid = bFlag
End Sub
My CVGridView1_ServerValidate sets args.IsValid to False if no checkboxes are checked in my Gridview, so I know it is processing the value correctly if no checkboxes are selected.
I am not sure how to display a message in the ValidationSummary if results are processed on server side?
Is there a way on client side to check to see if at least one checkbox has been selected?