Export (0) Print
Expand All

HtmlSelect.Size Property

Gets or sets the height (in rows) of the HtmlSelect control.

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

public int Size { get; set; }
/** @property */
public int get_Size ()

/** @property */
public void set_Size (int value)

public function get Size () : int

public function set Size (value : int)

Property Value

The height (in rows) of the HtmlSelect control.

Use the Size property to specify the height (in rows) of the HtmlSelect control. If you specify a size that is smaller than the number of items in the control, scroll bars are displayed to allow you to move up and down the list.

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.

The following code example demonstrates how to use the Size property to specify the height (in rows) of the HtmlSelect control.

<%@ 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>

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

Community Additions

ADD
Show:
© 2014 Microsoft