3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2014, 09:04 AM
Hi Rahul,
Please have look into the sample code snippet which works fine at my end.
ASPX:
C#:
Thanks,
Shinu.
Please have look into the sample code snippet which works fine at my end.
ASPX:
<telerik:RadListView ID="RadListView1" Width="97%" runat="server" DataSourceID="SqlDataSource1" ItemPlaceholderID="ProductsHolder"> <LayoutTemplate> <fieldset style="max-width: 920px;" id="FieldSet1"> <legend>Products</legend> <asp:Panel ID="ProductsHolder" runat="server" /> </fieldset> </LayoutTemplate> <ItemTemplate> <asp:CheckBoxList ID="CheckBoxList1" runat="server"> <asp:ListItem Text="Checked"> </asp:ListItem> <asp:ListItem Text="Unchecked"> </asp:ListItem> </asp:CheckBoxList> <asp:CustomValidator ID="CustomValidator2" runat="server" EnableClientScript="false" ErrorMessage="CustomValidator" OnServerValidate="CustomValidator2_ServerValidate"> </asp:CustomValidator> <telerik:RadListBox runat="server" ID="RadListBox1"> <Items> <telerik:RadListBoxItem Text="Item1" /> <telerik:RadListBoxItem Text="Item2" /> <telerik:RadListBoxItem Text="Item3" /> <telerik:RadListBoxItem Text="Item4" /> </Items> </telerik:RadListBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="RadListBox1"> </asp:RequiredFieldValidator> </ItemTemplate></telerik:RadListView><telerik:RadButton ID="RadButton2" runat="server" Text="Validate"></telerik:RadButton>C#:
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args){ foreach (RadListViewItem item in RadListView1.Items) { CheckBoxList list = (CheckBoxList)item.FindControl("CheckBoxList1"); for (int i = 0; i < list.Items.Count; i++) { if (list.Items[i].Selected == true) { args.IsValid = true; break; } else { args.IsValid = false; } } }}Thanks,
Shinu.
0
Rahul
Top achievements
Rank 1
answered on 16 Jan 2014, 10:39 AM
HI Shinu,
Thanks for quick reply, I want to do this client side validation using required field validatior at least one checkbox must be selected and my design code as follows.
Thanks for quick reply, I want to do this client side validation using required field validatior at least one checkbox must be selected and my design code as follows.
<tr> <td colspan="2"> <div style="border:solid 1px #EEEEEE; width:100%;"> <div style="border:1px solid gray;" id = "dvListView"> <telerik:RadListView runat="server" ID="RadListView1" onitemdatabound="RadListView1_ItemDataBound" BorderColor="White" BorderStyle="None" AllowPaging="True"> <ClientSettings></ClientSettings> <ItemTemplate> <div> <table> <tr> <td class="LabelWidth"> <asp:Label ID="Label4" runat="server" Text='<%# (DataBinder.Eval(Container.DataItem,"PermissionItemName")) %>'></asp:Label> </td> <td> <asp:CheckBoxList ID="Listbox_Permission" runat="server" RepeatDirection="Horizontal" CssClass="horizontalListbox"> </asp:CheckBoxList> </td> </tr> </table> </div> </ItemTemplate> </telerik:RadListView> <telerik:RadListBox ID="qw" runat="server" BorderColor="White" BorderStyle="None" DataValueField="PermissionItemOpearationId" DataTextField="PermissionOperationName" BorderWidth="0" AutoPostBack="false" CssClass="horizontalListbox"></telerik:RadListBox> <%-- <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="cb_selectone">Please check atleast one checkbox.</asp:CustomValidator>--%> </div> </div> </td> </tr><asp:Button ID="btn_new" CssClass="btn btn-sm btn-success" runat="server" Text="Submit" onclick="btn_new_Click" ValidationGroup="role" />
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2014, 04:39 AM
Hi Rahul,
I guess you want to show a RequierdFieldValidator for ASP CheckBoxList. But there is no field in the CheckBoxList to fill, so RequierdFieldValidator doesn't work for this Control. So you have to validate ASP CheckBoxList by CustomValidator. Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
I guess you want to show a RequierdFieldValidator for ASP CheckBoxList. But there is no field in the CheckBoxList to fill, so RequierdFieldValidator doesn't work for this Control. So you have to validate ASP CheckBoxList by CustomValidator. Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.