ListView.InsertItemTemplate プロパティ
定義
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 コントロールの挿入項目に対するカスタム コンテンツが格納されたオブジェクト。An object that contains the custom content for the insert item in the ListView control. 既定値は null
です。このプロパティが設定されていないことを示します。The default is null
, which indicates that this property is not set.
- 属性
例
次の例は、コントロールの挿入項目のカスタムテンプレートを定義する方法を示して ListView います。The following example shows how to define a custom template for the insert item of a ListView control. このコード例は、イベントに対して提供されるより大きな例の一部です ItemInserted 。This code example is part of a larger example provided for the ItemInserted event.
重要
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。This example has a text box that accepts user input, which is a potential security threat. 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 詳細については、「スクリプトによる攻略の概要」を参照してください。For more information, see Script Exploits Overview.
<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="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</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>
<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="|<< " LastPageText=" >>|"
NextPageText=" > " PreviousPageText=" < " />
</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>
<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 ます。Use the InsertItemTemplate property to define a custom user interface (UI) for the insert item in the ListView control. この UI は、表示されている項目の先頭または末尾に表示されます。This UI is rendered either at the start or at the end of the displayed items. UI が表示される場所は、プロパティを使用して指定し InsertItemPosition ます。You specify where the UI is rendered by using the InsertItemPosition property.
この InsertItemTemplate テンプレートには、通常、ユーザーが新しいレコードの値を入力するための入力コントロールが含まれています。The InsertItemTemplate template usually contains the input controls for the user to enter the values for a new record. また、通常は、レコードを挿入し、挿入操作をキャンセルするためのボタンやハイパーリンクが含まれています。It also usually contains buttons or hyperlinks to insert the record and to cancel the insert operation.
カスタムテンプレートを宣言によって指定するには、要素内に要素を追加し InsertItemTemplate
ListView
ます。To specify the custom template declaratively, add an InsertItemTemplate
element inside the ListView
element. その後、テンプレートの内容を要素に追加でき InsertItemTemplate
ます。You can then add the contents of the template to the InsertItemTemplate
element. 双方向のバインド式を使用して、フィールドを入力コントロールに関連付けることができます。You can associate a field with an input control by using a two-way binding expression. レコードが挿入されると、 ListView コントロールは、関連付けられている入力コントロールからフィールド値を自動的に抽出します。When a record is inserted, the ListView control automatically extracts the field value from the associated input control. 詳細については、「 データバインディング式の概要」を参照してください。For more information, see Data-Binding Expressions Overview.
組み込みのキャンセル操作と挿入操作を実行するボタンを作成するには、ボタンコントロールをテンプレートに追加します。To create buttons that perform the built-in cancel and insert operations, add a button control to the template. CommandNameプロパティを次の表に示すいずれかの値に設定します。Set its CommandName property to one of the values listed in the following table.
[ボタンの種類]Button type | CommandName 値CommandName value |
---|---|
CancelCancel | 中断"Cancel" |
挿入Insert | Insert"Insert" |
コントロール内の挿入項目の位置を制御する ListView には、プロパティを使用し InsertItemPosition ます。You can control the position of the insert item in the ListView control by using the InsertItemPosition property.