Creating a GroupBox in ASP.NET

Someone asked the other day in the newsgroups about creating a Windows-style groupbox in ASP.NET. I knew I had seen one used somewhere in a Web page, and finally tracked it down. It turns out to be the <fieldset> tag with an embedded <legend> to hold the text.

In ASP.NET, use the Panel control and provide a text value to the groupingtext attribute.

Here's some ASP.NET code:

<asp:panel id="Panel1" runat="server" groupingtext="Using the Fieldset Element">
    <table width="100%">
        <tr>
            <td>
                <asp:radiobutton id="radGrp1" runat="server" groupname="rads" />
            </td>
            <td>
                <asp:label id="lblLegend" runat="server" text="Use the Legend Tag!" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:radiobutton id="radGrp2" checked="true" groupname="rads" runat="server" /></td>
            <td>
                <asp:label id="lblGroup" runat="server" text="Creates a Groupbox in HTML!">
                </asp:label>
            </td>
        </tr>
    </table>
</asp:panel>

Here's the HTML spec's reference for the tag:

 http://www.w3.org/TR/html4/interact/forms.html#edef-FIELDSET

12 Comments

Comments have been disabled for this content.