다음을 통해 공유


HtmlSelect.Size 속성

정의

HtmlSelect 컨트롤의 높이(행 단위)를 가져오거나 설정합니다.

public:
 property int Size { int get(); void set(int value); };
public int Size { get; set; }
member this.Size : int with get, set
Public Property Size As Integer

속성 값

Int32

HtmlSelect 컨트롤의 높이(행 단위)입니다.

예제

다음 코드 예제에서는 컨트롤의 Size HtmlSelect 높이 (행)를 지정 하는 속성을 사용 하는 방법을 보여 줍니다.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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 />    -" + Select1.Items[i].Text;      

         }

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

      }

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

      }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title> HtmlSelect Example </title>
</head>
<body>
<form id="form1" runat="server">
   <div>

      <h3> HtmlSelect Example </h3>

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

      <select id="Select1" 
              multiple="true"
              runat="server">

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

      </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="selected"> 4 </option>
         <option value="5"> 5 </option>
         <option value="6"> 6 </option>

      </select>

        

      <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"/>

   </div>
</form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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 />    -" & Select1.Items(i).Text
           End If         
        Next

        Select1.Size = CInt(Select2.Value)

      End Sub

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

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title> HtmlSelect Example </title>
</head>
<body>
<form id="form1" runat="server">
   <div>

      <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="selected"> 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="selected"> 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>

        

      <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"/>

   </div>
</form>
</body>
</html>

설명

Size 속성을 사용하여 컨트롤의 높이(행)를 HtmlSelect 지정합니다. 컨트롤의 항목 수보다 작은 크기를 지정하면 스크롤 막대가 표시되어 목록을 위아래로 이동할 수 있습니다.

기본적으로 HtmlSelect 컨트롤은 드롭다운 목록 상자로 표시됩니다. 속성을 true여러 개 선택 Multiple 하도록 허용하거나 한 행보다 큰 높이를 지정하면(속성을 보다 1큰 값으로 설정Size) 컨트롤이 목록 상자로 표시됩니다.

적용 대상

추가 정보