DataList.SelectedItemStyle 속성

정의

DataList 컨트롤에서 선택한 항목의 스타일 속성을 가져옵니다.

public:
 virtual property System::Web::UI::WebControls::TableItemStyle ^ SelectedItemStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.TableItemStyle SelectedItemStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.SelectedItemStyle : System.Web.UI.WebControls.TableItemStyle
Public Overridable ReadOnly Property SelectedItemStyle As TableItemStyle

속성 값

TableItemStyle

TableItemStyle 컨트롤에서 선택한 항목의 스타일 속성이 들어 있는 DataList 개체입니다. 기본값은 빈 TableItemStyle 개체입니다.

특성

예제

다음 코드 예제에서는 컨트롤에서 선택한 항목 DataListSelectedItemStyle 대 한 사용자 지정 배경색을 지정 하는 속성을 사용 하는 방법을 보여 줍니다.

참고

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


<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!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>DataList Select Example</title>
<script runat="server">

      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataList control.
         DataTable dt = new DataTable();
         DataRow dr;
 
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("Item", typeof(Int32)));
         dt.Columns.Add(new DataColumn("Qty", typeof(Int32)));
         dt.Columns.Add(new DataColumn("Price", typeof(double)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = i * 2;
            dr[2] = 1.23 * (i + 1);
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;

      }
 
      void Page_Load(Object sender, EventArgs e) 
      {

         // Load sample data only once, when the page is first loaded.
         if (!IsPostBack) 
         {
            ItemsList.DataSource = CreateDataSource();
            ItemsList.DataBind();
         }

      }

      void Item_Command(Object sender, DataListCommandEventArgs e) 
      {
        
         // Set the SelectedIndex property to select an item in the DataList.
         ItemsList.SelectedIndex = e.Item.ItemIndex;

         // Rebind the data source to the DataList to refresh the control.
         ItemsList.DataSource = CreateDataSource();
         ItemsList.DataBind();

      }

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>DataList Select Example</h3>

      Click <b>Select</b> to select an item.

      <br /><br />
       
      <asp:DataList id="ItemsList"
           GridLines="Both"
           CellPadding="3"
           CellSpacing="0"           
           OnItemCommand="Item_Command"
           runat="server">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <SelectedItemStyle BackColor="Yellow">
         </SelectedItemStyle>

         <HeaderTemplate>

            Items

         </HeaderTemplate>
         
         <ItemTemplate>

            <asp:LinkButton id="SelectButton" 
                 Text="Select" 
                 CommandName="Select"
                 runat="server"/>

            Item <%# DataBinder.Eval(Container.DataItem, "Item") %>

         </ItemTemplate>
              
         <SelectedItemTemplate>

            Item:
            <asp:Label id="ItemLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Item") %>' 
                 runat="server"/>

            <br />

            Quantity:
            <asp:Label id="QtyLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Qty") %>' 
                 runat="server"/>

            <br />

            Price:
            <asp:Label id="PriceLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>' 
                 runat="server"/>

         </SelectedItemTemplate>

      </asp:DataList>

   </form>

</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!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>DataList Select Example</title>
<script runat="server">

      Function CreateDataSource() As ICollection 
      
         ' Create sample data for the DataList control.
         Dim dt As DataTable = New DataTable()
         Dim dr As DataRow
 
         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("Item", GetType(Int32)))
         dt.Columns.Add(New DataColumn("Qty", GetType(Int32)))
         dt.Columns.Add(New DataColumn("Price", GetType(Double)))
 
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 To 8 

            dr = dt.NewRow()
 
            dr(0) = i
            dr(1) = i * 2
            dr(2) = 1.23 * (i + 1)
 
            dt.Rows.Add(dr)
         
         Next i
 
         Dim dv As DataView = New DataView(dt)
         Return dv
      
      End Function
 
      Sub Page_Load(sender As Object, e As EventArgs) 

         ' Load sample data only once, when the page is first loaded.
         If Not IsPostBack Then 
         
            ItemsList.DataSource = CreateDataSource()
            ItemsList.DataBind()
         
         End If

      End Sub

      Sub Item_Command(sender As Object, e As DataListCommandEventArgs) 
        
         ' Set the SelectedIndex property to select an item in the DataList.
         ItemsList.SelectedIndex = e.Item.ItemIndex

         ' Rebind the data source to the DataList to refresh the control.
         ItemsList.DataSource = CreateDataSource()
         ItemsList.DataBind()

      End Sub

   </script>

</head>
<body>

   <form id="form1" runat="server">

      <h3>DataList Select Example</h3>

      Click <b>Select</b> to select an item.

      <br /><br />
       
      <asp:DataList id="ItemsList"
           GridLines="Both"
           CellPadding="3"
           CellSpacing="0"           
           OnItemCommand="Item_Command"
           runat="server">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <SelectedItemStyle BackColor="Yellow">
         </SelectedItemStyle>

         <HeaderTemplate>

            Items

         </HeaderTemplate>
         
         <ItemTemplate>

            <asp:LinkButton id="SelectButton" 
                 Text="Select" 
                 CommandName="Select"
                 runat="server"/>

            Item <%# DataBinder.Eval(Container.DataItem, "Item") %>

         </ItemTemplate>
              
         <SelectedItemTemplate>

            Item:
            <asp:Label id="ItemLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Item") %>' 
                 runat="server"/>

            <br />

            Quantity:
            <asp:Label id="QtyLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Qty") %>' 
                 runat="server"/>

            <br />

            Price:
            <asp:Label id="PriceLabel" 
                 Text='<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>' 
                 runat="server"/>

         </SelectedItemTemplate>

      </asp:DataList>

   </form>

</body>
</html>

설명

컨트롤에서 선택한 항목 DataList 에 대 한 사용자 지정 스타일을 제공 하려면이 속성을 사용 합니다. 조정할 수 있는 공통 스타일 특성 전경색, 배경색, 글꼴 및 셀 내용 맞춤을 포함 합니다. 모양을 향상 시킬 다른 스타일을 사용 하 여 DataList 컨트롤입니다.

항목의 스타일 속성을 DataList 제어 계층을 통해 다른 하나씩 스타일 속성에서 상속 됩니다. 계층에서 낮은 설정 항목 스타일 속성은 계층 구조의 상위 항목 스타일 속성에 의해 상속 됩니다. 예를 들어 빨강 글꼴을 지정 하는 경우는 ItemStyle 속성을 다른 항목 스타일의 모든 속성을 DataList 컨트롤 빨강 글꼴을 갖게 됩니다. 이 옵션을 사용 하면 단일 항목의 스타일 속성을 설정 하 여 컨트롤에 공통 된 모양을 제공할 수 있습니다. 스타일 속성을 설정 하 여 상위 계층에 있는 항목 스타일 속성에 대 한 상속 된 스타일 설정을 재정의할 수 있습니다. 예를 들어, 파랑 글꼴을 지정할 수 있습니다 합니다 AlternatingItemStyle 속성에 지정 된 빨간색 글꼴로 재정의 ItemStyle 속성입니다. 다음 표에서 순위가 가장 높은 계층 순서를 나열합니다.

우선 순위 스타일 속성
1 EditItemStyle
2 SelectedItemStyle
3 AlternatingItemStyle
4 ItemStyle
5 ControlStyle

선택한 항목에 대 한 사용자 지정 스타일을 지정 하려면 합니다 <SelectedItemStyle> 을 열고 닫는 태그 사이 DataList 제어 합니다. 다음을 표시 하 여 스타일 특성을 <SelectedItemStyle> 태그입니다.

적용 대상

추가 정보