TemplateField.InsertItemTemplate プロパティ
アセンブリ: System.Web (system.web.dll 内)

<TemplateContainerAttribute(GetType(IDataItemContainer), BindingDirection.TwoWay)> _ Public Overridable Property InsertItemTemplate As ITemplate
Dim instance As TemplateField Dim value As ITemplate value = instance.InsertItemTemplate instance.InsertItemTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)] public virtual ITemplate InsertItemTemplate { get; set; }
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection::TwoWay)] public: virtual property ITemplate^ InsertItemTemplate { ITemplate^ get (); void set (ITemplate^ value); }
/** @property */ public ITemplate get_InsertItemTemplate () /** @property */ public void set_InsertItemTemplate (ITemplate value)
public function get InsertItemTemplate () : ITemplate public function set InsertItemTemplate (value : ITemplate)
TemplateField の挿入モードの項目を表示するときに使用するテンプレートを格納している System.Web.UI.ITemplate 実装オブジェクト。既定値は null 参照 (Visual Basic では Nothing) です。このプロパティが設定されていないことを示します。

InsertItemTemplate プロパティを使用して、TemplateField オブジェクトの挿入モードの項目に表示するカスタムの内容を指定します。挿入モードの項目を表示する方法を指定するテンプレートを作成して、内容を定義します。
テンプレートを指定するには、まず、<TemplateField> 要素の開始タグと終了タグの間に <InsertItemTemplate> の開始タグと終了タグを配置します。次に、開始 <InsertItemTemplate> タグと終了 <InsertItemTemplate> タグの間にカスタムの内容を追加します。内容は、簡単なプレーンテキストとしたり、テンプレートに他のコントロールを埋め込んで複雑にしたりできます。
テンプレートで定義されたコントロールにプログラムからアクセスするには、まず、そのコントロールが、データ バインド コントロールの、どの TableCell オブジェクトに含まれるかを確認します。次に、TableCell オブジェクトの Controls コレクションを使用してコントロールにアクセスします。コントロールに ID プロパティが指定されている場合は、TableCell オブジェクトの FindControl メソッドを使用してコントロールを検索することもできます。
![]() |
---|
一部のデータ バインド コントロールではこのテンプレートがサポートされません。このテンプレートは、DetailsView コントロールのようにレコードを挿入できるデータ バインド コントロールだけでサポートされます。 |

InsertItemTemplate プロパティを使用して、DetailsView コントロールの TemplateField フィールド行に表示される挿入モードの項目のカスタム テンプレートを作成するコード例を次に示します。このテンプレートは、ユーザーが定義済み一覧から値を選択できる DropDownList コントロールを表示します。
<%@ Page language="VB" %> <script runat="server"> Sub StoresGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) ' Set the DataItemIndex property of the DetailsView control to display ' the record selected from the GridView control. ' StoresDetailView.DataItem = StoresGridView.SelectedIndex End Sub Sub StoresDetailView_ItemInserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs) ' Get the state value from the DropDownList control in the ' DetailsView control. Dim state As String = GetState() ' Add the state to the dictionary of values to ' insert into the database. e.Values("state") = state End Sub Sub StoresDetailView_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs) ' Refresh the GridView control after a new record is inserted. StoresGridView.DataBind() End Sub Function GetState() As String Dim state As String ' Get the DropDownList control that contains the state value ' in the DetailsView control. Dim list As DropDownList = CType(StoresDetailView.Rows(4).FindControl("StateList"), DropDownList) If Not list Is Nothing Then ' Get the selected value of the DropDownList control. state = list.SelectedItem.Text Else ' Set the state to an empty string (""). state = "" End If Return state End Function </script> <html> <body> <form runat="server"> <h3>TemplateField InsertItemTemplate Example</h3> <table cellspacing="10"> <tr> <td> <asp:gridview id="StoresGridView" datasourceid="StoresSqlDataSource" autogeneratecolumns="false" autogenerateselectbutton="true" datakeynames="stor_id" onselectedindexchanged="StoresGridView_SelectedIndexChanged" runat="server"> <headerstyle backcolor="Blue" forecolor="White"/> <columns> <asp:boundfield datafield="stor_name" headertext="Store Name"/> <asp:boundfield datafield="stor_address" headertext="Address"/> <asp:boundfield datafield="city" headertext="City"/> <asp:boundfield datafield="state" headertext="State"/> <asp:boundfield datafield="zip" headertext="ZIP Code"/> </columns> </asp:gridview> </td> <td valign="top"> <asp:detailsview id="StoresDetailView" datasourceid="StoresDetailsSqlDataSource" autogenerateinsertbutton="true" autogeneraterows="false" datakeynames="stor_id" gridlines="Both" oniteminserting="StoresDetailView_ItemInserting" oniteminserted="StoresDetailView_ItemInserted" runat="server"> <headerstyle backcolor="Navy" forecolor="White"/> <fields> <asp:boundfield datafield="stor_id" headertext="Store ID"/> <asp:boundfield datafield="stor_name" headertext="Store Name"/> <asp:boundfield datafield="stor_address" headertext="Address"/> <asp:boundfield datafield="city" headertext="City"/> <asp:templatefield headertext="State"> <itemtemplate> <%#Eval("state")%> </itemtemplate> <insertitemtemplate> <asp:dropdownlist id="StateList" datasourceid="StateSqlDataSource" datatextfield="state" runat="server"/> </insertitemtemplate> </asp:templatefield> <asp:boundfield datafield="zip" headertext="ZIP Code"/> </fields> </asp:detailsview> </td> </tr> </table> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="StoresSqlDataSource" selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> <asp:sqldatasource id="StoresDetailsSqlDataSource" selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" insertcommand="INSERT INTO stores([stor_id], [stor_name], [stor_address], [city], [state], [zip]) VALUES (@stor_id, @stor_name, @stor_address, @city, @state, @zip)" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> <!-- For this example, the states are retrieved from the --> <!-- state field. For your application, you should use a --> <!-- more complete source for the state values. --> <asp:sqldatasource id="StateSqlDataSource" selectcommand="SELECT Distinct [state] FROM [stores]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void StoresGridView_SelectedIndexChanged(Object sender, EventArgs e) { // Set the DataItemIndex property of the DetailsView control to display // the record selected from the GridView control. // StoresDetailView.DataItemIndex = StoresGridView.SelectedIndex; } void StoresDetailView_ItemInserting(Object sender, DetailsViewInsertEventArgs e) { // Get the state value from the DropDownList control in the // DetailsView control. String state = GetState(); // Add the state to the dictionary of values to // insert into the database. e.Values["state"] = state; } void StoresDetailView_ItemInserted (Object sender, DetailsViewInsertedEventArgs e) { // Refresh the GridView control after a new record is inserted. StoresGridView.DataBind (); } String GetState() { String state; // Get the DropDownList control that contains the state value // in the DetailsView control. DropDownList list = (DropDownList)StoresDetailView.Rows[4].FindControl("StateList"); if (list != null) { // Get the selected value of the DropDownList control. state = list.SelectedItem.Text; } else { // Set the state to an empty string (""). state = ""; } return state; } </script> <html> <body> <form runat="server"> <h3>TemplateField InsertItemTemplate Example</h3> <table cellspacing="10"> <tr> <td> <asp:gridview id="StoresGridView" datasourceid="StoresSqlDataSource" autogeneratecolumns="false" autogenerateselectbutton="true" datakeynames="stor_id" onselectedindexchanged="StoresGridView_SelectedIndexChanged" runat="server"> <headerstyle backcolor="Blue" forecolor="White"/> <columns> <asp:boundfield datafield="stor_name" headertext="Store Name"/> <asp:boundfield datafield="stor_address" headertext="Address"/> <asp:boundfield datafield="city" headertext="City"/> <asp:boundfield datafield="state" headertext="State"/> <asp:boundfield datafield="zip" headertext="ZIP Code"/> </columns> </asp:gridview> </td> <td valign="top"> <asp:detailsview id="StoresDetailView" datasourceid="StoresDetailsSqlDataSource" autogenerateinsertbutton="true" autogeneraterows="false" datakeynames="stor_id" gridlines="Both" oniteminserting="StoresDetailView_ItemInserting" oniteminserted="StoresDetailView_ItemInserted" runat="server"> <headerStyle backcolor="Navy" forecolor="White"/> <Fields> <asp:boundfield datafield="stor_id" headertext="Store ID"/> <asp:boundfield datafield="stor_name" headertext="Store Name"/> <asp:boundfield datafield="stor_address" headertext="Address"/> <asp:boundfield datafield="city" headertext="City"/> <asp:templatefield headertext="State"> <itemtemplate> <%#Eval("state")%> </itemtemplate> <insertitemtemplate> <asp:dropdownlist id="StateList" datasourceid="StateSqlDataSource" datatextfield="state" runat="server"/> </insertitemtemplate> </asp:templatefield> <asp:boundfield datafield="zip" headertext="ZIP Code"/> </Fields> </asp:detailsview> </td> </tr> </table> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="StoresSqlDataSource" selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> <asp:sqldatasource id="StoresDetailsSqlDataSource" selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" insertcommand="INSERT INTO stores([stor_id], [stor_name], [stor_address], [city], [state], [zip]) VALUES (@stor_id, @stor_name, @stor_address, @city, @state, @zip)" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> <!-- For this example, the states are retrieved from the --> <!-- state field. For your application, you should use a --> <!-- more complete source for the state values. --> <asp:sqldatasource id="StateSqlDataSource" selectcommand="SELECT Distinct [state] FROM [stores]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TemplateField.InsertItemTemplate プロパティのページへのリンク