Click here to Skip to main content
15,892,674 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 97.9K   1.6K   40  
An ASP.NET DropDownList custom control with the HTML OptionGroup feature.
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="UseWithObjectDataSource.aspx.cs"
    Inherits="TestWebApplication.UseWithObjectDataSource" MasterPageFile="~/Site1.Master"
    Title="UseWithObjectDataSource" %>

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

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <div>
        Choose food:
        <ddlb:optiongroupselect id="ogsFinishedProduct" runat="server" appenddatabounditems="True"
            autopostback="True" datatextfield="food" datavaluefield="id">
                <ddlb:OptionGroupItem ID="OptionGroupItem1" runat="server" Value="-1" Text="-- Select --" Selected="True" />
            </ddlb:optiongroupselect>
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" />
    </div>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetByFinishedProduct" TypeName="TestWebApplication.DataClassForObjectDataSource">
        <SelectParameters>
            <asp:ControlParameter ControlID="ogsFinishedProduct" Name="id" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
</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