Validate DropDownCheckBoxes control using RequiredField validator in ASP.Net

Last Reply on Feb 02, 2015 10:18 PM By Mudassar

Posted on Feb 02, 2015 10:17 PM

This my code plz help me thank you

<cc2:DropDownCheckBoxes ID="cblCustomerList" runat="server" Width="180px">
    <Style SelectBoxWidth="195" DropDownBoxBoxWidth="160" DropDownBoxBoxHeight="195"/>
                   <Items>
                              <asp:ListItem Text = "Kidneys Donor" Value = "Kidneys Donor"></asp:ListItem>
                        <asp:ListItem Text = "Lungs Donor" Value = "Lungs Donor" >Eye Donor</asp:ListItem>
                        <asp:ListItem Text = "Pancreas Donor" Value = "Pancreas Donor" >Blood Donor</asp:ListItem>
                        <asp:ListItem Text = "One" Value = "1">Heart Donor</asp:ListItem>
                         <asp:ListItem Text = "One" Value = "1" >Liver Donor</asp:ListItem>
                          <asp:ListItem  >Kidneys Donor</asp:ListItem>
                           <asp:ListItem>Lungs Donor</asp:ListItem>
                            <asp:ListItem>Pancreas Donor</asp:ListItem>
                             <asp:ListItem>Intestines Donor</asp:ListItem>
                              <asp:ListItem>Cornea Donor</asp:ListItem>
                               <asp:ListItem>Skin Donor</asp:ListItem>
                                <asp:ListItem>Heart Valves Donor</asp:ListItem>
                                 <asp:ListItem>Tendons Donor</asp:ListItem>
                        </Items>

             </cc2:DropDownCheckBoxes>
        

 

Posted on Feb 02, 2015 10:18 PM Modified on on Feb 02, 2015 10:24 PM

You will need to use the ExtendedRequiredFieldValidator control provided in the same DLL as shown below.

Download

Download the DLL from here

HTML

<%@ Register TagPrefix="asp" Namespace="Saplin.Controls" Assembly="DropDownCheckBoxes" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:DropDownCheckBoxes ID="DropDownCheckBoxes1" runat="server" Width="180px">
        <Style SelectBoxWidth="195" DropDownBoxBoxWidth="160" DropDownBoxBoxHeight="90" />
        <Items>
            <asp:ListItem Text="Mango" Value="1"></asp:ListItem>
            <asp:ListItem Text="Apple" Value="2"></asp:ListItem>
            <asp:ListItem Text="Banana" Value="3"></asp:ListItem>
        </Items>
    </asp:DropDownCheckBoxes>
    &nbsp;
    <asp:ExtendedRequiredFieldValidator ID = "ExtendedRequiredFieldValidator1" runat = "server" ControlToValidate = "DropDownCheckBoxes1" ErrorMessage = "Required" ForeColor = "Red"></asp:ExtendedRequiredFieldValidator>
    <br />
    <br />
    <asp:Button Text="Submit" runat="server" />
    </form>
</body>
</html>

Screenshot