Export (0) Print
Expand All

HtmlSelect.Items Property

Gets a collection that contains the items listed in an HtmlSelect control.

Namespace:  System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

public ListItemCollection Items { get; }

Property Value

Type: System.Web.UI.WebControls.ListItemCollection
A System.Web.UI.WebControls.ListItemCollection that contains the items listed in an HtmlSelect control.

Use the Items collection to manage the items listed in the HtmlSelect control. You can programmatically add items to, remove items from, and insert items into the collection.

The Items collection is commonly used to iterate through the items in the HtmlSelect control. For example, when multiple items are selected, you can iterate through the Items collection to determine which items are selected.

The following code example demonstrates how to use the Items collection to iterate through the items in the HtmlSelect control and determine which items are selected.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">

    void Button_Click (Object sender, EventArgs e)

        Label1.Text = "You selected:";

        for (int i = 0; i <= Select1.Items.Count - 1; i++)
           if (Select1.Items[i].Selected)
              Label1.Text += "<br /> &nbsp;&nbsp; -" + Select1.Items[i].Text;



<html xmlns="http://www.w3.org/1999/xhtml" >

    <title> HtmlSelect Example </title>
<form id="form1" runat="server">

    <h3> HtmlSelect Example </h3>

    Select items from the list: <br /><br />

    <select id="Select1" 

        <option value="1" selected="selected"> Item 1 </option>
        <option value="2"> Item 2 </option>
        <option value="3"> Item 3 </option>
        <option value="4"> Item 4 </option>
        <option value="5"> Item 5 </option>
        <option value="6"> Item 6 </option>

    <br /><br />

    <button id="Button1"


    <br /><br />

    <asp:Label id="Label1"


.NET Framework

Supported in: 4.6, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft