TemplateField.InsertItemTemplate プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TemplateField.InsertItemTemplate プロパティの意味・解説 

TemplateField.InsertItemTemplate プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

TemplateField オブジェクト挿入モードの項目を表示するときに使用するテンプレート取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: 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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TemplateField クラス
TemplateField メンバ
System.Web.UI.WebControls 名前空間
TemplateField.AlternatingItemTemplate プロパティ
TemplateField.EditItemTemplate プロパティ
TemplateField.FooterTemplate プロパティ
TemplateField.HeaderTemplate プロパティ
ItemTemplate



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TemplateField.InsertItemTemplate プロパティ」の関連用語

TemplateField.InsertItemTemplate プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TemplateField.InsertItemTemplate プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS