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

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

TemplateField.ItemTemplate プロパティ

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

データ バインド コントロールの項目を表示するときに使用するテンプレート取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<TemplateContainerAttribute(GetType(IDataItemContainer), BindingDirection.TwoWay)>
 _
Public Overridable Property
 ItemTemplate As ITemplate
Dim instance As TemplateField
Dim value As ITemplate

value = instance.ItemTemplate

instance.ItemTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)]
 
public virtual ITemplate ItemTemplate { get;
 set; }
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection::TwoWay)]
 
public:
virtual property ITemplate^ ItemTemplate {
    ITemplate^ get ();
    void set (ITemplate^ value);
}
/** @property */
public ITemplate get_ItemTemplate ()

/** @property */
public void set_ItemTemplate (ITemplate value)
public function get ItemTemplate
 () : ITemplate

public function set ItemTemplate
 (value : ITemplate)

プロパティ
TemplateField の項目を表示するときに使用するテンプレート格納している System.Web.UI.ITemplate 実装オブジェクト既定値null 参照 (Visual Basic では Nothing) です。このプロパティ設定されていないことを示します

解説解説

ItemTemplate プロパティ使用してTemplateField オブジェクトの項目に表示するカスタム内容指定します。項目を表示する方法指定するテンプレート作成して内容定義します

メモメモ

オプションで AlternatingItemTemplate プロパティItemTemplate プロパティ組み合わせて定義してデータ バインド コントロールの項目を 1 つおきに異な外観設定できます

テンプレート指定するには、まず、<TemplateField> 要素開始タグ終了タグの間に <ItemTemplate>開始タグ終了タグ配置します次に開始 <ItemTemplate> タグ終了 <ItemTemplate> タグの間にカスタム内容追加します内容は、簡単なプレーンテキストとしたり、テンプレートに他のコントロール埋め込んで複雑にしたりできます

テンプレート定義されコントロールプログラムかアクセスするには、まず、そのコントロールが、データ バインド コントロールの、どの TableCell オブジェクト含まれるかを確認します次にTableCell オブジェクトControls コレクション使用してコントロールアクセスます。コントロールID プロパティ指定されている場合は、TableCell オブジェクトの FindControl メソッド使用してコントロール検索することもできます

使用例使用例

ItemTemplate プロパティ使用して、GridView コントロールTemplateField フィールド表示される項目カスタム テンプレート作成するコード例次に示します。このテンプレートは、RadioButtonList コントロールフィールドの値を表示します

<%@ Page language="VB" %>

<script runat="server">

  Sub TitleGridView_RowDataBound(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)
    
    ' Get the RadioButtonList control from the row.
    Dim radio As RadioButtonList = CType(e.Row.FindControl("TypeList"),
 RadioButtonList)
    
    ' Select the appropriate option button based on the value
    ' of the Type field for the row. In this example, the Type
    ' field values are stored in the hidden column in the 
    ' GridView control.
    If Not radio Is Nothing
 Then

      Select Case e.Row.Cells(3).Text.Trim()

        Case "business"
          radio.SelectedIndex = 0

        Case "mod_cook"
          radio.SelectedIndex = 1

        Case "popular_comp"
          radio.SelectedIndex = 2

        Case "psychology"
          radio.SelectedIndex = 3

        Case "trad_cook"
          radio.SelectedIndex = 4

        Case Else
          radio.SelectedIndex = 5
      
      End Select
      
    End If
    
  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>TemplateField ItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively. -->
      <!-- Create a custom TemplateField column that uses      -->
      <!-- two Label controls to display an author's
 first and -->
      <!-- last name in the same column.                  
     -->
      <asp:gridview id="TitleGridView" 
        datasourceid="TitleSqlDataSource" 
        autogeneratecolumns="false"
        onrowdatabound="TitleGridView_RowDataBound"
 
        runat="server">
                
        <columns>
          
          <asp:boundfield datafield="title"
            headertext="Title"/>
          
          <asp:boundfield datafield="price"
            dataformatstring="{0:c}"
            headertext="Price"/>  
                  
          <asp:templatefield headertext="Type">
            <itemtemplate>
              <asp:radiobuttonlist id="TypeList"
                datasourceid="TypeSqlDataSource"
                datatextfield="type"
                enabled="false"  
                runat="server"/>  
            </itemtemplate>
          </asp:templatefield>
          
          <asp:boundfield datafield="type"
            visible="false"/>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
     -->
      <asp:sqldatasource id="TitleSqlDataSource"
  
        selectcommand="SELECT [title], [price], [type] FROM [titles]"
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
      
      <asp:sqldatasource id="TypeSqlDataSource"
  
        selectcommand="SELECT Distinct [type] FROM [titles]"
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<script runat="server">

  void TitleGridView_RowDataBound (Object sender, GridViewRowEventArgs
 e)
  {
    
    // Get the RadioButtonList control from the row.
    RadioButtonList radio = (RadioButtonList)e.Row.FindControl("TypeList");
    
    // Select the appropriate option button based on the value
    // of the Type field for the row. In this example, the Type
    // field values are stored in the hidden column in the 
    // GridView control.
    if (radio != null)
    {
      switch (e.Row.Cells[3].Text.Trim())
      {
        case "business":
          radio.SelectedIndex = 0; 
          break;

        case "mod_cook":
          radio.SelectedIndex = 1; 
          break;

        case "popular_comp":
          radio.SelectedIndex = 2; 
          break;

        case "psychology":
          radio.SelectedIndex = 3; 
          break;

        case "trad_cook":
          radio.SelectedIndex = 4; 
          break;

        default:
          radio.SelectedIndex = 5; 
          break;
      }
    }
    
  }
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>TemplateField ItemTemplate Example</h3>

      <!-- Populate the Columns collection declaratively. -->
      <!-- Create a custom TemplateField column that uses      -->
      <!-- two Label controls to display an author's first and -->
      <!-- last name in the same column.                  
     -->
      <asp:gridview id="TitleGridView" 
        datasourceid="TitleSqlDataSource" 
        autogeneratecolumns="false"
        onrowdatabound="TitleGridView_RowDataBound" 
        runat="server">
                
        <columns>
          
          <asp:boundfield datafield="title"
            headertext="Title"/>
          
          <asp:boundfield datafield="price"
            dataformatstring="{0:c}"
            headertext="Price"/>  
                  
          <asp:templatefield headertext="Type">
            <itemtemplate>
              <asp:radiobuttonlist id="TypeList"
                datasourceid="TypeSqlDataSource"
                datatextfield="type"
                enabled="false"  
                runat="server"/>  
            </itemtemplate>
          </asp:templatefield>
          
          <asp:boundfield datafield="type"
            visible="false"/>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="TitleSqlDataSource"  
        selectcommand="SELECT [title], [price], [type] FROM [titles]"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
      
      <asp:sqldatasource id="TypeSqlDataSource"  
        selectcommand="SELECT Distinct [type] FROM [titles]"
        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 プロパティ
TemplateField.InsertItemTemplate プロパティ


このページでは「.NET Framework クラス ライブラリ リファレンス」からTemplateField.ItemTemplate プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTemplateField.ItemTemplate プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTemplateField.ItemTemplate プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS