ListItem.Enabled 속성

정의

목록 항목의 활성화 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

속성 값

Boolean

목록 항목이 활성화되면 true이고, 그렇지 않으면 false입니다. 기본값은 true입니다.

예제

다음 예제에서는 컨트롤에서 Enabled 목록 항목을 RadioButtonList 프로그래밍 방식으로 사용 하지 않도록 설정 하는 속성을 사용 하는 방법을 보여 줍니다. 첫 번째 질문은 사용자에게 사용자의 직업에 해당하는 라디오 단추를 선택하도록 요청합니다. 사용자가 개발자가 아니라고 표시하면 두 번째 라디오 단추 목록의 목록 항목이 비활성화됩니다. 두 번째 질문은 사용자에게 기본 프로그래밍 언어를 선택하도록 요청합니다. 이 질문은 개발자가 아닌 사용자와 관련이 없습니다.

참고

다음 코드 샘플 단일 파일 코드 모델을 사용 하 고 코드 숨김 파일에 직접 복사 하는 경우 제대로 작동 하지 않을 수 있습니다. 이 코드 샘플.aspx 확장명이 있는 빈 텍스트 파일에 복사 해야 합니다. Web Forms 코드 모델에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지 코드 모델합니다.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ListItem.Enabled Property Example</title>
<script runat="server">         
  
    protected void  Index_Changed(object sender, EventArgs e)
    {

        // if the user is not a developer, do not
        // ask the user to select a programming language.
        if (RadioButtonList1.SelectedIndex == 2)
        {   
            // Clear any previously selected list 
            // items in the second question.
            RadioButtonList2.SelectedIndex = -1;

            // Disable all the list items in the second question.
            for (int i = 0; i < RadioButtonList2.Items.Count; i++)
            {
                RadioButtonList2.Items[i].Enabled = false;
            }
        }          
        else
        // Enable all the list items in the second question.
            for (int i = 0; i < RadioButtonList2.Items.Count; i++)
        {
            RadioButtonList2.Items[i].Enabled = true;
        }
    }
</script>
  </head>

  <body>
    <form id="form1" runat="server">
        
      <h3>ListItem.Enabled Property Example</h3>
      
      Select your occupation:
      <asp:radiobuttonlist id="RadioButtonList1"
        autopostback="true"
        onselectedindexchanged="Index_Changed" 
    runat="server">             
      <asp:ListItem>Web developer</asp:ListItem>
      <asp:ListItem>Windows developer</asp:ListItem>
      <asp:ListItem>Occupation other than developer</asp:ListItem>
        </asp:radiobuttonlist>
          
    <br /><br />
          
    Select your primary programming language:
        <asp:radiobuttonlist id="RadioButtonList2" 
      runat="server">             
       <asp:ListItem>Visual Basic .NET</asp:ListItem>
       <asp:ListItem>C#</asp:ListItem>
       <asp:ListItem>C++</asp:ListItem>
       <asp:ListItem>Other</asp:ListItem>
    </asp:radiobuttonlist> 
                  
    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ListItem.Enabled Property Example</title>
<script runat="server">         
  
      Sub Index_Changed(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim i As Integer

        ' If the user is not a developer, do not
        ' ask the user to select a programming language.
        If radiobuttonlist1.SelectedIndex = 2 Then
          ' Clear any previously selected list 
          ' items in the second question.
          Radiobuttonlist2.SelectedIndex = -1

          ' Disable all the list items in the second question.
          For i = 0 To Radiobuttonlist2.Items.Count - 1
            Radiobuttonlist2.Items(i).Enabled = False
          Next
          
        Else
          ' Enable all the list items in the second question.
          For i = 0 To Radiobuttonlist2.Items.Count - 1
            Radiobuttonlist2.Items(i).Enabled = True
          Next i

        End If
      End Sub
    
      </script>
  </head>

  <body>
    <form id="form1" runat="server">
        
      <h3>ListItem.Enabled Property Example</h3>
      
      Select your occupation:
      <asp:radiobuttonlist id="RadioButtonList1"
        autopostback="true"
        onselectedindexchanged="Index_Changed" 
    runat="server">             
      <asp:ListItem>Web developer</asp:ListItem>
      <asp:ListItem>Windows developer</asp:ListItem>
      <asp:ListItem>Occupation other than developer</asp:ListItem>
        </asp:radiobuttonlist>
          
    <br /><br />
          
    Select your primary programming language:
        <asp:radiobuttonlist id="RadioButtonList2" 
      runat="server">             
       <asp:ListItem>Visual Basic .NET</asp:ListItem>
       <asp:ListItem>C#</asp:ListItem>
       <asp:ListItem>C++</asp:ListItem>
       <asp:ListItem>Other</asp:ListItem>
    </asp:radiobuttonlist> 
                  
    </form>      
  </body>
</html>

설명

Enabled 속성을 사용하면 컨트롤을 사용할지 여부를 ListItem 지정할 수 있습니다. ListItem 사용하지 않도록 설정된 컨트롤은 선택할 수 없음을 나타내기 위해 흐리게 표시됩니다. 컨트롤 또는 CheckBoxList 컨트롤에서 RadioButtonList 컨트롤을 ListItem 사용 하지 않도록 설정 하려면이 속성을 사용 합니다.

참고

컨트롤 또는 ListBox 컨트롤에서 DropDownList 컨트롤을 ListItem 사용 하지 않도록 설정 하려면이 속성을 사용할 수 없습니다.

적용 대상

추가 정보