This documentation is archived and is not being maintained.

HtmlSelect.Multiple Property

Gets or sets a value indicating whether multiple items can be selected concurrently in the HtmlSelect control.

[Visual Basic]
Public Property Multiple As Boolean
[C#]
public bool Multiple {get; set;}
[C++]
public: __property bool get_Multiple();
public: __property void set_Multiple(bool);
[JScript]
public function get Multiple() : Boolean;
public function set Multiple(Boolean);

Property Value

true if multiple items can be concurrently selected in the HtmlSelect control; otherwise, false. The default value is false.

Remarks

Use the Multiple property to specify whether multiple items can be concurrently selected in the HtmlSelect control.

By default, the HtmlSelect control is displayed as a drop-down list box. If you allow multiple selections (by setting the Multiple property to true) or specify a height greater than one row (by setting the Size property to a value greater than 1), the control is displayed as a list box.

To determine the selected items in an HtmlSelect control that allows multiple simultaneous selections, iterate through the Items collection and test the ListItem.Selected property of each item.

Note   The multiple attribute is rendered in the HtmlSelect control only if this property is set to true.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Multiple property to specify whether multiple items can be selected in the HtmlSelect control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      Sub Button_Click (sender As Object, e As EventArgs)
        
         Dim i As Integer

         Label1.Text = "You selected:"

         For i = 0 to Select1.Items.Count - 1
  
            If Select1.Items(i).Selected Then
               Label1.Text = Label1.Text & "<br> &nbsp;&nbsp; -" & Select1.Items(i).Text
            End If         

         Next i

         Select1.Size = CInt(Select2.Value)

      End Sub

      Sub Check_Changed (sender As Object, e As EventArgs)
        
         Select1.Multiple = CheckBox1.Checked

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select item(s) from the list: <br><br>

      <select id="Select1" 
              Multiple="True"
              runat="server">

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

      </select>

      <hr>

      HtmlSelect Size: <br>

      <select id="Select2" 
              runat="server">

         <option value="1" Selected="True"> 1 </option>
         <option value="2"> 2 </option>
         <option value="3"> 3 </option>
         <option value="4"> 4 </option>
         <option value="5"> 5 </option>
         <option value="6"> 6 </option>

      </select>

      &nbsp;&nbsp;

      <asp:CheckBox id="CheckBox1"
           Text="Enable Multiple Property"
           AutoPostBack="True"
           OnCheckedChanged="Check_Changed"
           Checked="True"
           runat="server"/>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

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

<html>

<head>

   <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;      

         }

         Select1.Size = Convert.ToInt32(Select2.Value);

      }

      void Check_Changed (Object sender, EventArgs e)
      {
        
         Select1.Multiple = CheckBox1.Checked;

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select item(s) from the list: <br><br>

      <select id="Select1" 
              Multiple="True"
              runat="server">

         <option value="1" Selected="True"> 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>

      </select>

      <hr>

      HtmlSelect Size: <br>

      <select id="Select2" 
              runat="server">

         <option value="1"> 1 </option>
         <option value="2"> 2 </option>
         <option value="3"> 3 </option>
         <option value="4" Selected="True"> 4 </option>
         <option value="5"> 5 </option>
         <option value="6"> 6 </option>

      </select>

      &nbsp;&nbsp;

      <asp:CheckBox id="CheckBox1"
           Text="Enable Multiple Property"
           AutoPostBack="True"
           OnCheckedChanged="Check_Changed"
           Checked="True"
           runat="server"/>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>

<head>

   <script runat="server">

      function Button_Click (sender:  Object, e : EventArgs) : void
      {

         Label1.Text = "You selected:";

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

         }

         Select1.Size = Convert.ToInt32(Select2.Value);

      }

      function Check_Changed  (sender : Object, e : EventArgs) : void
      {
        
         Select1.Multiple = CheckBox1.Checked;

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlSelect Example </h3>

      Select item(s) from the list: <br><br>

      <select id="Select1" 
              Multiple="True"
              runat="server">

         <option value="1" Selected="True"> 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>

      </select>

      <hr>

      HtmlSelect Size: <br>

      <select id="Select2" 
              runat="server">

         <option value="1"> 1 </option>
         <option value="2"> 2 </option>
         <option value="3"> 3 </option>
         <option value="4" Selected="True"> 4 </option>
         <option value="5"> 5 </option>
         <option value="6"> 6 </option>

      </select>

      &nbsp;&nbsp;

      <asp:CheckBox id="CheckBox1"
           Text="Enable Multiple Property"
           AutoPostBack="True"
           OnCheckedChanged="Check_Changed"
           Checked="True"
           runat="server"/>

      <br><br>

      <button id="Button1"
              OnServerClick="Button_Click"
              runat="server">

         Submit

      </button>

      <br><br>

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>

</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlSelect Class | HtmlSelect Members | System.Web.UI.HtmlControls Namespace | Size

Show: