ListItem.Selected 속성

정의

항목이 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Selected { bool get(); void set(bool value); };
public bool Selected { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.MinimizableAttributeTypeConverter))]
public bool Selected { get; set; }
member this.Selected : bool with get, set
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.MinimizableAttributeTypeConverter))>]
member this.Selected : bool with get, set
Public Property Selected As Boolean

속성 값

Boolean

해당 항목이 선택되면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

특성

예제

다음 예제에서는 컨트롤의 CheckBoxList 컬렉션을 반복 Items 할 때 속성을 사용하여 Selected 선택된 확인란을 확인하는 방법을 보여 줍니다.

참고

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

<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>
    <title>ASP.NET Example</title>
</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 id="form1" action="checkboxlist.aspx" 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>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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>
    <title>ASP.NET Example</title>
</head>
 <body>
    <script language="VB" runat="server">
       Sub Check_Clicked(sender As Object, e As EventArgs)
          Message.Text = "Selected Item(s):<br /><br />"
          Dim i As Integer
          For i = 0 To checkboxlist1.Items.Count - 1
             If checkboxlist1.Items(i).Selected Then
                Message.Text = Message.Text & checkboxlist1.Items(i).Text & "<br />"
             End If
          Next
       End Sub
    </script>
 
    <form id="form1" action="checkboxlist.aspx" 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>

설명

속성이 Selected 포함된 목록 컨트롤에서 현재 선택되어 있는지 여부를 ListItem 확인하려면 이 속성을 사용합니다. 이 속성은 일반적으로 사용 됩니다 목록 컨트롤에서 개체의 ListItem 컬렉션을 반복할 때 항목이 선택 되어 있는지 여부를 확인 합니다.

적용 대상

추가 정보