Click here to Skip to main content
15,895,557 members
Articles / Web Development / ASP.NET

DropDownList with OptionGroup

Rate me:
Please Sign up or sign in to vote.
4.79/5 (24 votes)
19 Jun 2008CPOL3 min read 98K   1.6K   40  
An ASP.NET DropDownList custom control with the HTML OptionGroup feature.
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="TestRequiredFieldValidator.aspx.cs"
    Inherits="TestWebApplication.TestRequiredFieldValidator" MasterPageFile="~/Site1.Master"
    Title="TestRequiredFieldValidator" %>

<%@ Register TagPrefix="ddlb" Assembly="OptionDropDownList" Namespace="OptionDropDownList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <div>
        <ddlb:OptionGroupSelect ID="OptionGroupSelect1" runat="server" Width="300px">
            <ddlb:OptionGroupItem ID="OptionGroupItem0" runat="server" Value="0" Text="-- Select --"
                Selected="true" />
            <ddlb:OptionGroupItem ID="OptionGroupItem1" runat="server" Value="1" Text="UNE" OptionGroup="Odd" />
            <ddlb:OptionGroupItem ID="OptionGroupItem2" runat="server" Value="2" Text="TWO" OptionGroup="Even" />
            <ddlb:OptionGroupItem ID="OptionGroupItem3" runat="server" Value="3" Text="TREE"
                OptionGroup="Odd" />
            <ddlb:OptionGroupItem ID="OptionGroupItem4" runat="server" Value="4" Text="FOUR"
                OptionGroup="Even" />
        </ddlb:OptionGroupSelect>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please choose a value"
            ControlToValidate="OptionGroupSelect1" InitialValue="0">*</asp:RequiredFieldValidator><br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
        <br />
        <br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
    </div>
</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions