ListView.InsertItemTemplate プロパティ

定義

ListView コントロールの挿入項目に対するカスタム コンテンツを取得または設定します。

public:
 virtual property System::Web::UI::ITemplate ^ InsertItemTemplate { 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.ListViewItem), System.ComponentModel.BindingDirection.TwoWay)]
public virtual System.Web.UI.ITemplate InsertItemTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListViewItem), System.ComponentModel.BindingDirection.TwoWay)>]
member this.InsertItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property InsertItemTemplate As ITemplate

プロパティ値

コントロール内の挿入項目のカスタム コンテンツを格納している ListView オブジェクト。 既定値は null です。このプロパティが設定されていないことを示します。

属性

次の例は、コントロールの挿入項目のカスタム テンプレートを定義する方法を ListView 示しています。 このコード例は、 イベントに対して提供されるより大きな例の ItemInserted 一部です。

重要

この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<asp:ListView ID="ContactsListView" 
  DataSourceID="ContactsDataSource" 
  DataKeyNames="ContactID"
  OnItemInserted="ContactsListView_ItemInserted"  
  InsertItemPosition="LastItem"
  runat="server">
  <LayoutTemplate>
    <table cellpadding="2" border="1" runat="server" id="tblContacts" width="640px">
      <tr runat="server" id="itemPlaceholder" />
    </table>
    <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
      <Fields>
        <asp:NextPreviousPagerField 
          ShowFirstPageButton="true" ShowLastPageButton="true"
          FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
          NextPageText=" &gt; " PreviousPageText=" &lt; " />
      </Fields>
    </asp:DataPager>
  </LayoutTemplate>
  <ItemTemplate>
    <tr runat="server">
      <td valign="top">
        <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
        <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
      </td>
      <td>&nbsp;
        <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
      </td>
    </tr>
  </ItemTemplate>
  <InsertItemTemplate>
    <tr style="background-color:#D3D3D3">
      <td valign="top">
        <asp:Label runat="server" ID="FirstNameLabel" 
          AssociatedControlID="FirstNameTextBox" Text="First Name"/>
        <asp:TextBox ID="FirstNameTextBox" runat="server" 
          Text='<%#Bind("FirstName") %>' /><br />
        <asp:Label runat="server" ID="LastNameLabel" 
          AssociatedControlID="LastNameTextBox" Text="Last Name" />
        <asp:TextBox ID="LastNameTextBox" runat="server" 
          Text='<%#Bind("LastName") %>' /><br />
        <asp:Label runat="server" ID="EmailLabel" 
          AssociatedControlID="EmailTextBox" Text="Email" />
        <asp:TextBox ID="EmailTextBox" runat="server" 
          Text='<%#Bind("EmailAddress") %>' />
      </td>
      <td>
        <asp:LinkButton ID="InsertButton" runat="server" 
          CommandName="Insert" Text="Insert" />
      </td>
    </tr>
  </InsertItemTemplate>
</asp:ListView>
<asp:ListView ID="ContactsListView" 
  DataSourceID="ContactsDataSource" 
  DataKeyNames="ContactID"
  OnItemInserted="ContactsListView_ItemInserted"  
  InsertItemPosition="LastItem"
  runat="server">
  <LayoutTemplate>
    <table cellpadding="2" border="1" runat="server" id="tblContacts" width="640px">
      <tr runat="server" id="itemPlaceholder" />
    </table>
    <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
      <Fields>
        <asp:NextPreviousPagerField 
          ShowFirstPageButton="true" ShowLastPageButton="true"
          FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
          NextPageText=" &gt; " PreviousPageText=" &lt; " />
      </Fields>
    </asp:DataPager>
  </LayoutTemplate>
  <ItemTemplate>
    <tr runat="server">
      <td valign="top">
        <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
        <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
      </td>
      <td>&nbsp;
        <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
      </td>
    </tr>
  </ItemTemplate>
  <InsertItemTemplate>
    <tr style="background-color:#D3D3D3">
      <td valign="top">
        <asp:Label runat="server" ID="FirstNameLabel" 
          AssociatedControlID="FirstNameTextBox" Text="First Name"/>
        <asp:TextBox ID="FirstNameTextBox" runat="server" 
          Text='<%#Bind("FirstName") %>' /><br />
        <asp:Label runat="server" ID="LastNameLabel" 
          AssociatedControlID="LastNameTextBox" Text="Last Name" />
        <asp:TextBox ID="LastNameTextBox" runat="server" 
          Text='<%#Bind("LastName") %>' /><br />
        <asp:Label runat="server" ID="EmailLabel" 
          AssociatedControlID="EmailTextBox" Text="Email" />
        <asp:TextBox ID="EmailTextBox" runat="server" 
          Text='<%#Bind("EmailAddress") %>' />
      </td>
      <td>
        <asp:LinkButton ID="InsertButton" runat="server" 
          CommandName="Insert" Text="Insert" />
      </td>
    </tr>
  </InsertItemTemplate>
</asp:ListView>

注釈

プロパティを InsertItemTemplate 使用して、コントロール内の挿入項目のカスタム ユーザー インターフェイス (UI) を ListView 定義します。 この UI は、表示される項目の先頭または末尾にレンダリングされます。 UI をレンダリングする場所を指定するには、 プロパティを InsertItemPosition 使用します。

テンプレートには InsertItemTemplate 、通常、ユーザーが新しいレコードの値を入力するための入力コントロールが含まれています。 また、通常は、レコードを挿入したり、挿入操作を取り消したりするためのボタンまたはハイパーリンクも含まれています。

カスタム テンプレートを宣言的に指定するには、 要素内に 要素をInsertItemTemplateListView追加します。 その後、テンプレートの内容を 要素に InsertItemTemplate 追加できます。 双方向バインディング式を使用して、フィールドを入力コントロールに関連付けることができます。 レコードが挿入されると、 ListView コントロールは関連付けられている入力コントロールからフィールド値を自動的に抽出します。 詳細については、「 データ バインディング式の概要」を参照してください。

組み込みのキャンセル操作と挿入操作を実行するボタンを作成するには、テンプレートにボタン コントロールを追加します。 プロパティを CommandName 次の表に示す値のいずれかに設定します。

[ボタンの種類] CommandName 値
キャンセル "Cancel"
挿入 "挿入"

プロパティを使用して、コントロール内の挿入項目の ListView 位置を InsertItemPosition 制御できます。

適用対象

こちらもご覧ください