Export (0) Print
Expand All
3 out of 8 rated this helpful - Rate this topic

ListControl.Items Property

Gets the collection of items in the list control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual ListItemCollection Items { get; }
/** @property */
public ListItemCollection get_Items ()

public function get Items () : ListItemCollection

Property Value

A ListItemCollection that represents the items within the list. The default is an empty list.

Use this property to get the properties of items in the list control. This property can be used to determine the selected items in the list control.

TopicLocation
How to: Set Web Server Control Properties in CollectionsBuilding ASP .NET Web Applications
How to: Set Web Server Control Properties in CollectionsBuilding ASP .NET Web Applications

The following example demonstrates how to use the Items property to determine the selected items in a CheckBoxList control.

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 <body>
    <script language="C#" runat="server">
       void Check_Clicked(Object sender, EventArgs e) {
          Message.Text="Selected Item(s):" + "<br>" + "<br>";
          for (int i=0; i<checkboxlist1.Items.Count; i++) {
             if (checkboxlist1.Items[i].Selected)
                Message.Text=Message.Text + checkboxlist1.Items[i].Text + "<br>";
          }
       }
    </script>
 
    <form method="post" runat="server">
 
       <asp:CheckBoxList id="checkboxlist1" runat="server"
            AutoPostBack="True"
            CellPadding="5"
            CellSpacing="5"
            RepeatColumns="2"
            RepeatDirection="Vertical"
            RepeatLayout="Flow"
            TextAlign="Right"
            OnSelectedIndexChanged="Check_Clicked">
 
          <asp:ListItem>Item 1</asp:ListItem>
          <asp:ListItem>Item 2</asp:ListItem>
          <asp:ListItem>Item 3</asp:ListItem>
          <asp:ListItem>Item 4</asp:ListItem>
          <asp:ListItem>Item 5</asp:ListItem>
          <asp:ListItem>Item 6</asp:ListItem>
 
       </asp:CheckBoxList>
 
       <br><br>
       <asp:label id="Message" runat="server"/>
             
    </form>
         
 </body>
 </html>
    

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.