I currently have a Gridview, and I want to use client-side validation to ensure that a row has been selected (ie: SelectedIndex > -1).
At the moment I'm using <asp:CustomValidator>
but want to move away from server-side validation. Here is what I'm currently doing:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="MSN" DataField="MSN" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<asp:CustomValidator ID="cvSelected" runat="server" ErrorMessage="Please select!" />
And then in code behind:
Private Sub cvSelected_ServerValidate(ByVal source As Object, ByVal args As _
System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvSelected.ServerValidate
args.IsValid = (GridView1.SelectedIndex > -1)
End Sub