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

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

DataList.ItemTemplate プロパティ

DataList コントロールの項目のテンプレート取得または設定します

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

<TemplateContainerAttribute(GetType(DataListItem))> _
Public Overridable Property
 ItemTemplate As ITemplate
Dim instance As DataList
Dim value As ITemplate

value = instance.ItemTemplate

instance.ItemTemplate = value
[TemplateContainerAttribute(typeof(DataListItem))] 
public virtual ITemplate ItemTemplate { get;
 set; }
[TemplateContainerAttribute(typeof(DataListItem))] 
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)

プロパティ
DataList コントロールの項目のテンプレート格納している System.Web.UI.ITemplate。既定値null 参照 (Visual Basic では Nothing) です。

解説解説

ItemTemplate プロパティ使用してDataList コントロールの項目の内容制御しますDataList コントロールの項目の外観は、ItemStyle プロパティによって制御します

DataList コントロールの項目のテンプレート指定するには、<ItemTemplate> タグDataList コントロール開始タグ終了タグの間に配置しますその後<ItemTemplate>開始タグ終了タグの間に、テンプレート内容リスト記述できます

AlternatingItemTemplate プロパティ使用してDataList コントロール交互の項目に異な外観指定することもできます

注意に関するメモ注意

このコントロールは、ユーザー入力表示するために使用できますユーザー入力には悪意のあるクライアント スクリプト含まれている可能性ありますアプリケーション表示する前にクライアントから送信され実行スクリプトSQL ステートメントなどのコード情報はすべて検証してください入力テキストコントロール表示する前に検証コントロール使用してユーザー入力検証できますASP.NET には入力要求検証機能があり、ユーザー入力の中のスクリプトおよび HTMLブロックできます詳細については、「標準コントロールセキュリティ保護」、「方法 : HTML エンコーディング文字列適用して Web アプリケーションスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力検証」を参照してください

使用例使用例

ItemTemplate プロパティ使用してDataList コントロールの項目の内容制御する方法コード例次に示します

メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<%@ Import Namespace="System.Data"
 %>
 
<html>
   <script runat="server">
 
      Function CreateDataSource() As ICollection
 
      
         ' Create sample data for the DataList control.
         Dim dt As DataTable = New
 DataTable()
         dim dr As DataRow
 
         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue",
 GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue",
 GetType(String)))
         dt.Columns.Add(New DataColumn("CurrencyValue",
 GetType(Double)))
         dt.Columns.Add(New DataColumn("ImageValue",
 GetType(String)))
 
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 To 8 

            dr = dt.NewRow()
 
            dr(0) = i
            dr(1) = "Description for item " &
 i.ToString()
            dr(2) = 1.23 * (i + 1)
            dr(3) = "Image" & i.ToString() &
 ".jpg"
 
            dt.Rows.Add(dr)

         Next i
 
         Dim dv As DataView = New
 DataView(dt)
         Return dv

      End Function
 
      Sub Page_Load(sender As Object,
 e As EventArgs) 

         ' Load sample data only once, when the page is first loaded.
         If Not IsPostBack Then
 
     
            ItemsList.DataSource = CreateDataSource()
            ItemsList.DataBind()
         
         End If

      End Sub
 
      Sub Button_Click(sender As Object,
 e As EventArgs) 
 
         ' Set the repeat direction based on the selected value of the
         ' DirectionList DropDownList control.
         ItemsList.RepeatDirection = _
             CType(DirectionList.SelectedIndex, RepeatDirection)

         ' Set the repeat layout based on the selected value of the
         ' LayoutList DropDownList control.
         ItemsList.RepeatLayout = CType(LayoutList.SelectedIndex, RepeatLayout)

         ' Set the number of columns to display based on the selected
         ' value of the ColumnsList DropDownList control.
         ItemsList.RepeatColumns = ColumnsList.SelectedIndex

         ' Show or hide the gridlines based on the value of the
         ' ShowBorderCheckBox. Note that gridlines are displayed
         ' only if the RepeatLayout property is set to Table.
         If ShowBorderCheckBox.Checked _
             And ItemsList.RepeatLayout = RepeatLayout.Table Then
 

            ItemsList.BorderWidth = Unit.Pixel(1)
            ItemsList.GridLines = GridLines.Both
         
         Else  
    
            ItemsList.BorderWidth = Unit.Pixel(0)
            ItemsList.GridLines = GridLines.None
         
         End If
    
      End Sub    
 
   </script>
 
<body>
 
   <form runat=server>

      <h3>DataList Example</h3>
 
      <asp:DataList id="ItemsList"
           BorderColor="black"
           CellPadding="5"
           CellSpacing="5"
           RepeatDirection="Vertical"
           RepeatLayout="Table"
           RepeatColumns="0"
           ShowBorder="False"
           runat="server">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            List of items

         </HeaderTemplate>
               
         <ItemTemplate>

            Description: <br>
            <%# DataBinder.Eval(Container.DataItem, "StringValue")
 %>

            <br>

            Price: <%# DataBinder.Eval(Container.DataItem, "CurrencyValue",
 "{0:c}") %>

            <br>

            <asp:Image id="ProductImage"
                 ImageUrl='<%# DataBinder.Eval(Container.DataItem,
 "ImageValue") %>'
                 runat="server"/>

         </ItemTemplate>
 
      </asp:DataList>
 
      <hr>

      <table cellpadding="5">

         <tr>

            <td>

               Repeat direction:

            <td>

            <td>

               Repeat layout:

            <td>

            <td>

               Repeat columns:

            <td>

            <td>

               <asp:CheckBox id="ShowBorderCheckBox"
                    Text="Show border"
                    Checked="False" 
                    runat="server" />

            <td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="DirectionList"
 
                    runat="server">

                  <asp:ListItem>Horizontal</asp:ListItem>
                  <asp:ListItem Selected="True">Vertical</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               <asp:DropDownList id="LayoutList"
 
                    runat="server">

                  <asp:ListItem Selected="True">Table</asp:ListItem>
                  <asp:ListItem>Flow</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               <asp:DropDownList id="ColumnsList"
 
                    runat="server">

                  <asp:ListItem Selected="True">0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               &nbsp;

            <td>


         </tr>

      </table>     
         
      <asp:LinkButton id="RefreshButton" 
           Text="Refresh DataList" 
           OnClick="Button_Click" 
           runat="server"/>
 
   </form>
 
</body>
</html>

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <script runat="server">
 
      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataList control.
         DataTable dt = new DataTable();
         DataRow dr;
 
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue",
 typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue",
 typeof(String)));
         dt.Columns.Add(new DataColumn("CurrencyValue",
 typeof(double)));
         dt.Columns.Add(new DataColumn("ImageValue",
 typeof(String)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Description for item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
            dr[3] = "Image" + i.ToString() + ".jpg";
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;
      }
 
 
      void Page_Load(Object sender, EventArgs e) 
      {

         // Load sample data only once, when the page is first loaded.
         if (!IsPostBack) 
         {
            ItemsList.DataSource = CreateDataSource();
            ItemsList.DataBind();
         }

      }
 
      void Button_Click(Object sender, EventArgs e) 
      {
 
         // Set the repeat direction based on the selected value of
 the
         // DirectionList DropDownList control.
         ItemsList.RepeatDirection = 
             (RepeatDirection)DirectionList.SelectedIndex;

         // Set the repeat layout based on the selected value of the
         // LayoutList DropDownList control.
         ItemsList.RepeatLayout = (RepeatLayout)LayoutList.SelectedIndex;

         // Set the number of columns to display based on the selected
         // value of the ColumnsList DropDownList control.
         ItemsList.RepeatColumns = ColumnsList.SelectedIndex;

         // Show or hide the gridlines based on the value of the
         // ShowBorderCheckBox property. Note that gridlines are displayed
         // only if the RepeatLayout property is set to Table.
         if ((ShowBorderCheckBox.Checked) 
             && (ItemsList.RepeatLayout == RepeatLayout.Table)) 
         {
            ItemsList.BorderWidth = Unit.Pixel(1);
            ItemsList.GridLines = GridLines.Both;
         }    
         else  
         {
            ItemsList.BorderWidth = Unit.Pixel(0);
            ItemsList.GridLines = GridLines.None;
         }
    
      }    
 
   </script>
 
<body>
 
   <form runat=server>

      <h3>DataList Example</h3>
 
      <asp:DataList id="ItemsList"
           BorderColor="black"
           CellPadding="5"
           CellSpacing="5"
           RepeatDirection="Vertical"
           RepeatLayout="Table"
           RepeatColumns="0"
           ShowBorder="False"
           runat="server">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            List of items

         </HeaderTemplate>
               
         <ItemTemplate>

            Description: <br>
            <%# DataBinder.Eval(Container.DataItem, "StringValue") %>

            <br>

            Price: <%# DataBinder.Eval(Container.DataItem, "CurrencyValue",
 "{0:c}") %>

            <br>

            <asp:Image id="ProductImage"
                 ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageValue")
 %>'
                 runat="server"/>

         </ItemTemplate>
 
      </asp:DataList>
 
      <hr>

      <table cellpadding="5">

         <tr>

            <td>

               Repeat direction:

            <td>

            <td>

               Repeat layout:

            <td>

            <td>

               Repeat columns:

            <td>

            <td>

               <asp:CheckBox id="ShowBorderCheckBox"
                    Text="Show border"
                    Checked="False" 
                    runat="server" />

            <td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="DirectionList" 
                    runat="server">

                  <asp:ListItem>Horizontal</asp:ListItem>
                  <asp:ListItem Selected="True">Vertical</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               <asp:DropDownList id="LayoutList" 
                    runat="server">

                  <asp:ListItem Selected="True">Table</asp:ListItem>
                  <asp:ListItem>Flow</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               <asp:DropDownList id="ColumnsList" 
                    runat="server">

                  <asp:ListItem Selected="True">0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            <td>

            <td>

               &nbsp;

            <td>


         </tr>

      </table>     
         
      <asp:LinkButton id="RefreshButton" 
           Text="Refresh DataList" 
           OnClick="Button_Click" 
           runat="server"/>
 
   </form>
 
</body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS