다음을 통해 공유


TemplateField.AlternatingItemTemplate 속성

정의

TemplateField 개체에서 교대로 반복되는 항목을 표시하기 위한 템플릿을 가져오거나 설정합니다.

public:
 virtual property System::Web::UI::ITemplate ^ AlternatingItemTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.IDataItemContainer), System.ComponentModel.BindingDirection.TwoWay)]
public virtual System.Web.UI.ITemplate AlternatingItemTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.IDataItemContainer), System.ComponentModel.BindingDirection.TwoWay)>]
member this.AlternatingItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property AlternatingItemTemplate As ITemplate

속성 값

ITemplate

ITemplate에서 교대로 반복되는 항목을 표시하기 위한 템플릿이 들어 있는 TemplateField 구현 개체입니다. 기본값은 null로, 이 속성이 설정되어 있지 않음을 나타냅니다.

특성

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 AlternatingItemTemplate 교대로 반복 되는 사용자 지정 템플릿을 만들려면 속성 항목을 TemplateField 의 필드 열을 GridView 컨트롤. 템플릿에 지정 된 템플릿의 변형은 ItemTemplate 속성을 셀의 반대쪽에 이미지로 표시 되는 위치입니다.


<%@ 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>TemplateField AlternatingItemTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>TemplateField AlternatingItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively.    -->
      <!-- Create a TemplateField field column that has both      -->
      <!-- an  item template and an alternating item template.    -->
      <!-- The item template displays an author's image on the    -->
      <!-- left side of the column, while the alternating item    -->
      <!-- template displays an author's image on the right side. -->
      
      <!-- For this example, the zip field is used for the        -->
      <!-- values of the image URL. For your application, you     -->
      <!-- should use a field that contains valid URLs to         -->
      <!-- images.                                                -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:templatefield headertext="Author">
            <itemtemplate>
              <asp:image id="LeftAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"  
                runat="server"/>
              <asp:label id="LeftFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="LeftLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
            </itemtemplate>
            <alternatingitemtemplate>
              <asp:label id="RightFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="RightLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
              <asp:image id="RightAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"
                runat="server"/>
            </alternatingitemtemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [zip] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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>TemplateField AlternatingItemTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>TemplateField AlternatingItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively.    -->
      <!-- Create a TemplateField field column that has both      -->
      <!-- an  item template and an alternating item template.    -->
      <!-- The item template displays an author's image on the    -->
      <!-- left side of the column, while the alternating item    -->
      <!-- template displays an author's image on the right side. -->
      
      <!-- For this example, the zip field is used for the        -->
      <!-- values of the image URL. For your application, you     -->
      <!-- should use a field that contains valid URLs to         -->
      <!-- images.                                                -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="False"
        runat="server">
                
        <columns>
                
          <asp:templatefield headertext="Author">
            <itemtemplate>
              <asp:image id="LeftAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"  
                runat="server"/>
              <asp:label id="LeftFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="LeftLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
            </itemtemplate>
            <alternatingitemtemplate>
              <asp:label id="RightFirstNameLabel"
                text= '<%# Eval("au_fname") %>'
                runat="server"/> 
              <asp:label id="RightLastNameLabel"
                text= '<%# Eval("au_lname") %>'
                runat="server"/>
              <asp:image id="RightAuthorImage"
                imageurl='<%# Eval("zip") %>'
                alternatetext="Author Photo"
                runat="server"/>
            </alternatingitemtemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname], [zip] FROM [authors]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

설명

사용 된 AlternatingItemTemplate 교대로 반복 되는 항목에 대해 표시 되는 사용자 지정 내용을 지정 하는 속성을 TemplateField 개체입니다. 교대로 반복 되는 항목을 렌더링 하는 방법을 지정 하는 템플릿을 만들어 콘텐츠를 정의 합니다.

참고

AlternatingItemTemplate 속성은 주로 함께에서 사용 합니다 ItemTemplate 데이터 바인딩된 컨트롤에서 모든 다른 항목에 대 한 다른 모양을 만들 속성입니다.

서식 파일을 지정 하려면 먼저 배치 열고 닫는 <AlternatingItemTemplate> 을 열고 닫는 태그 사이 <TemplateField> 요소입니다. 다음으로 열기 및 닫기 사이 있는 사용자 지정 내용을 추가 <AlternatingItemTemplate> 태그입니다. 콘텐츠는 일반 텍스트 만큼 간단 하거나 복잡 (다른 컨트롤 템플릿에 포함, 예를 들어) 수 있습니다.

템플릿에 정의 된 컨트롤에 프로그래밍 방식으로 액세스 하려면 먼저 결정 TableCell 개체 데이터 바인딩된 컨트롤에서 컨트롤을 포함 합니다. 다음을 사용 하 여는 Controls 의 컬렉션을 TableCell 컨트롤에 액세스 하는 개체입니다. 사용할 수도 있습니다는 FindControl 메서드를 TableCell 개체를 컨트롤에 컨트롤을 찾을 ID 지정 된 속성입니다.

적용 대상

추가 정보