ListView.AlternatingItemTemplate Właściwość

Definicja

Pobiera lub ustawia zawartość niestandardową dla zmiennego elementu danych w kontrolce ListView .

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.WebControls.ListViewDataItem), 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.WebControls.ListViewDataItem), System.ComponentModel.BindingDirection.TwoWay)>]
member this.AlternatingItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property AlternatingItemTemplate As ITemplate

Wartość właściwości

ITemplate

Obiekt, który zawiera zawartość niestandardową dla zmiennego elementu danych w kontrolce ListView . Wartość domyślna to null, która wskazuje, że ta właściwość nie jest ustawiona.

Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak używać szablonu AlternatingItemTemplate do definiowania stylu zmian elementów danych w kontrolce ListView .

<%@ 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 id="Head1" runat="server">
    <title>ListView AlternatingItemTemplate Example</title>
    <style type="text/css">
        body   
        {
          font-size: 10pt;
            font-family: Trebuchet MS, Arial, Tahoma;
            text-align:center;
        }
        .item { background-color: #E0FFFF }
        .alternatingItem { background-color: #B0E0E6 }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
      
      <h3>ListView AlternatingItemTemplate Example</h3>
      
      <asp:ListView ID="VendorsListView" 
        DataSourceID="VendorsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px" id="tblVendors" runat="server">
            <tr runat="server">
              <th runat="server">ID</th>
              <th runat="server">Account Number</th>
              <th runat="server">Name</th>
              <th runat="server">Preferred Vendor</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager ID="VendorsDataPager" runat="server" PageSize="15">
            <Fields>
              <asp:NumericPagerField ButtonCount="10" />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr class="item" runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" Enabled="False"
                Checked='<%# Eval("PreferredVendorStatus") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr class="alternatingItem" runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" Enabled="False"
                Checked='<%# Eval("PreferredVendorStatus") %>' />
            </td>
          </tr>
        </AlternatingItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->
      <asp:SqlDataSource ID="VendorsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT VendorID, AccountNumber, Name, PreferredVendorStatus 
          FROM Purchasing.Vendor WHERE (ActiveFlag = 1)" >
      </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 id="Head1" runat="server">
    <title>ListView AlternatingItemTemplate Example</title>
    <style type="text/css">
        body   
        {
          font-size: 10pt;
            font-family: Trebuchet MS, Arial, Tahoma;
            text-align:center;
        }
        .item { background-color: #E0FFFF }
        .alternatingItem { background-color: #B0E0E6 }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
      
      <h3>ListView AlternatingItemTemplate Example</h3>
      
      <asp:ListView ID="VendorsListView" 
        DataSourceID="VendorsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="640px" id="tblVendors" runat="server">
            <tr runat="server">
              <th runat="server">ID</th>
              <th runat="server">Account Number</th>
              <th runat="server">Name</th>
              <th runat="server">Preferred Vendor</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager ID="VendorsDataPager" runat="server" PageSize="15">
            <Fields>
              <asp:NumericPagerField ButtonCount="10" />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr class="item" runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" Enabled="False"
                Checked='<%# Eval("PreferredVendorStatus") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr class="alternatingItem" runat="server">
            <td>
              <asp:Label ID="VendorIDLabel" runat="server" Text='<%# Eval("VendorID") %>' />
            </td>
            <td>
              <asp:Label ID="AccountNumberLabel" runat="server" Text='<%# Eval("AccountNumber") %>' />
            </td>
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td align="center">
              <asp:CheckBox ID="PreferredCheckBox" runat="server" Enabled="False"
                Checked='<%# Eval("PreferredVendorStatus") %>' />
            </td>
          </tr>
        </AlternatingItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->
      <asp:SqlDataSource ID="VendorsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT VendorID, AccountNumber, Name, PreferredVendorStatus 
          FROM Purchasing.Vendor WHERE (ActiveFlag = 1)" >
      </asp:SqlDataSource>
    </form>
  </body>
</html>

Uwagi

Użyj właściwości , AlternatingItemTemplate aby zdefiniować niestandardowy interfejs użytkownika dla zmiennego elementu danych. Szablon AlternatingItemTemplate zwykle zawiera te same kontrolki i zawartość co ItemTemplate szablon, ale z innym wyglądem do odróżnienia elementów.

Aby określić szablon niestandardowy deklaratywne, dodaj AlternatingItemTemplate element wewnątrz kontrolki ListView . Następnie dodaj kontrolki i zawartość między tagami otwierania i zamykania <AlternatingItemTemplate> . Aby wyświetlić wartości pól ze źródła danych, użyj wyrażenia powiązania danych. Aby uzyskać więcej informacji, zobacz Omówienie wyrażeń powiązań danych.

Aby utworzyć przyciski, które automatycznie wybierają, usuwają i edytują operacje, dodaj kontrolkę przycisku do szablonu. Ustaw jej CommandName właściwość na jedną z wartości wymienionych w poniższej tabeli.

Typ przycisku Wartość CommandName
Usuń "Usuń"
Edytuj "Edytuj"
Wybierz pozycję "Wybierz"

Dotyczy

Zobacz też