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

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

DataGrid.ItemStyle プロパティ

DataGrid コントロールの項目のスタイル プロパティ取得します

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

Public Overridable ReadOnly
 Property ItemStyle As TableItemStyle
Dim instance As DataGrid
Dim value As TableItemStyle

value = instance.ItemStyle
public virtual TableItemStyle ItemStyle { get;
 }
public:
virtual property TableItemStyle^ ItemStyle {
    TableItemStyle^ get ();
}
/** @property */
public TableItemStyle get_ItemStyle ()
public function get ItemStyle
 () : TableItemStyle

プロパティ
DataGrid コントロールの項目のスタイル プロパティ格納している TableItemStyle オブジェクト既定値は空の TableItemStyle オブジェクトです。

解説解説

このプロパティ使用してDataGrid コントロールの項目のカスタム スタイル指定します調整できる共通スタイル属性には、前景色、背景色フォントセル内の内容配置などがあります異なスタイル指定すると、DataGrid コントロール外観詳細に設定されます。

DataGrid コントロールの項目スタイル プロパティは、優先順位に従って、ある項目スタイル プロパティから別の項目スタイル プロパティへと継承されます。優先順位の高い項目スタイル プロパティは、優先順位が低い項目スタイル プロパティの値を継承します。たとえば、ItemStyle プロパティに赤いフォント指定すると、DataGrid コントロールの他のすべての項目スタイル プロパティにも赤いフォント設定されます。これにより、単一の項目スタイル プロパティ設定するだけで、コントロール全体的な外観統一感を持たせることができます優先順位の高い項目スタイル プロパティ継承したスタイル設定無効にする場合は、そのスタイル プロパティに独自の値を設定します。たとえば、AlternatingItemStyle プロパティに青いフォント指定してItemStyle プロパティ指定した赤いフォントオーバーライドできます優先順位を高い方から低い方への順序次の表に示します

優先順位

スタイル プロパティ

1

EditItemStyle

2

SelectedItemStyle

3

AlternatingItemStyle

4

ItemStyle

5

ControlStyle

DataGrid コントロールの項目のカスタム スタイル指定するには、<ItemStyle> タグDataGrid コントロール開始タグ終了タグの間に配置しますその後<ItemStyle>開始タグ内にスタイル属性リスト記述できます

AlternatingItemStyle プロパティ使用してDataGrid コントロール交互の項目に異な外観指定できます

使用例使用例

ItemStyle プロパティ使用してDataGrid の項目の背景色黄色に設定する方法次のコード例示します

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<%@ Import Namespace="System.Data"
 %>
 
 <html>
 <script language="VB" runat="server">
 
    Dim Cart As DataTable
    Dim CartView As DataView
    
    Function CreateDataSource() As ICollection
        Dim dt As New DataTable()
        Dim dr As DataRow
        
        dt.Columns.Add(New DataColumn("IntegerValue",
 GetType(Int32)))
        dt.Columns.Add(New DataColumn("StringValue",
 GetType(String)))
        dt.Columns.Add(New DataColumn("CurrencyValue",
 GetType(Double)))
        
        Dim i As Integer
        For i = 0 To 9
            dr = dt.NewRow()
            
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = 1.23 *(i + 1)
            
            dt.Rows.Add(dr)
        Next i
        
        Dim dv As New DataView(dt)
        Return dv
    End Function 'CreateDataSource


    Sub Page_Load(sender As Object,
 e As EventArgs)
        
        If Not IsPostBack Then
            ' Load this data only once.
            ItemsGrid.DataSource = CreateDataSource()
            ItemsGrid.DataBind()
        End If
    End Sub 'Page_Load 
 
 </script>
 
 <body>
 
    <form runat=server>

       <h3>DataGrid Example</h3>
 
       <asp:DataGrid id="ItemsGrid" runat="server"
            BorderColor="black"
            BorderWidth="1"
            CellPadding="10"
            ShowFooter="true"
            AutoGenerateColumns="true">

          <HeaderStyle BackColor="#00aaaa">
          </HeaderStyle>

          <ItemStyle BackColor="yellow">
          </ItemStyle>

          <FooterStyle BackColor="#00aaaa">
          </FooterStyle>

       </asp:DataGrid>
 
    </form>
 
 </body>
 </html>

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
 <html>
 <script language="C#" runat="server">
 
    DataTable Cart;
    DataView CartView;
 
    ICollection CreateDataSource() 
    {
       DataTable dt = new DataTable();
       DataRow dr;
 
       dt.Columns.Add(new DataColumn("IntegerValue",
 typeof(Int32)));
       dt.Columns.Add(new DataColumn("StringValue",
 typeof(string)));
       dt.Columns.Add(new DataColumn("CurrencyValue",
 typeof(double)));
 
       for (int i = 0; i < 10; i++) 
       {
          dr = dt.NewRow();
 
          dr[0] = i;
          dr[1] = "Item " + i.ToString();
          dr[2] = 1.23 * (i+1);
 
          dt.Rows.Add(dr);
       }
 
       DataView dv = new DataView(dt);
       return dv;
    }
 
    void Page_Load(Object sender, EventArgs e) 
    {
 
       if (!IsPostBack) 
       {
          // Load this data only once.
          ItemsGrid.DataSource= CreateDataSource();
          ItemsGrid.DataBind();
       }
 
    }
 
 </script>
 
 <body>
 
    <form runat=server>

       <h3>DataGrid Example</h3>
 
       <asp:DataGrid id="ItemsGrid" runat="server"
            BorderColor="black"
            BorderWidth="1"
            CellPadding="10"
            ShowFooter="true"
            AutoGenerateColumns="true">

          <HeaderStyle BackColor="#00aaaa">
          </HeaderStyle>

          <ItemStyle BackColor="yellow">
          </ItemStyle>

          <FooterStyle BackColor="#00aaaa">
          </FooterStyle>

       </asp:DataGrid>
 
    </form>
 
 </body>
 </html>

<%@ Page Language="JScript" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
 <html>
 <script language="JScript" runat="server">
 
      var Cart : DataTable;
      var CartView : DataView;
 
      function CreateDataSource() : ICollection 
      {
       
         var dt : DataTable = new DataTable();
         var dr : DataRow;
 
         dt.Columns.Add(new DataColumn("IntegerValue",
 Int32));
         dt.Columns.Add(new DataColumn("StringValue",
 System.String));
         dt.Columns.Add(new DataColumn("CurrencyValue",
 double));
 
         for (var i : int
 = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i+1);
 
            dt.Rows.Add(dr);
         }
 
         var dv : DataView = new DataView(dt);
         return dv;
      }
 
    function Page_Load(sender, e : EventArgs) 
    {
 
       if (!IsPostBack) 
       {
          // Load this data only once.
          ItemsGrid.DataSource= CreateDataSource();
          ItemsGrid.DataBind();
       }
 
    }
 
 </script>
 
 <body>
 
    <form runat=server>

       <h3>DataGrid Example</h3>
 
       <asp:DataGrid id="ItemsGrid" runat="server"
            BorderColor="black"
            BorderWidth="1"
            CellPadding="10"
            ShowFooter="true"
            AutoGenerateColumns="true">

          <HeaderStyle BackColor="#00aaaa">
          </HeaderStyle>

          <ItemStyle BackColor="yellow">
          </ItemStyle>

          <FooterStyle BackColor="#00aaaa">
          </FooterStyle>

       </asp:DataGrid>
 
    </form>
 
 </body>
 </html>

<%@ Page Language="VB" AutoEventWireup="True"
 %>
<%@ Import Namespace="System.Data"
 %>
 
<html>
   <script runat="server">
 
      Function CreateDataSource() As ICollection
 
      
         ' Create sample data for the DataGrid 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)))
 
         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 to 4 
        
            dr = dt.NewRow()
 
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = 1.23 * (i + 1)
 
            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
 
  
            ItemsGrid.DataSource = CreateDataSource()
            ItemsGrid.DataBind()

         End If

      End Sub

      Sub Selection_Change(sender As Object,
 e As EventArgs)

         ' Set the background color for the items and alternating items
 in
         ' the DataGrid control. Notice that the ItemStyle property
 affects
         ' the even-numbered items, while the AlternatingItemStyle property
 
         ' affects the odd-numbered items.
         ItemsGrid.ItemStyle.BackColor = _
             System.Drawing.Color.FromName(ItemBackColorList.SelectedItem.Value)
         ItemsGrid.AlternatingItemStyle.BackColor = _
             System.Drawing.Color.FromName(AltItemBackColorList.SelectedItem.Value)

      End Sub

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGrid ItemStyle and AlternatingItemStyle Example</h3>

      Select background colors for the items
 and alternating items.

      <br><br>
 
      <b>Product List</b>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="False"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <ItemStyle BackColor="White">
         </ItemStyle>

         <AlternatingItemStyle BackColor="White">
         </AlternatingItemStyle>

         <Columns>

            <asp:BoundColumn DataField="IntegerValue"
 
                 HeaderText="Item"/>

            <asp:BoundColumn DataField="StringValue"
 
                 HeaderText="Description"/>

            <asp:BoundColumn DataField="CurrencyValue"
 
                 HeaderText="Price"
                 DataFormatString="{0:c}">

               <ItemStyle HorizontalAlign="Right">
               </ItemStyle>

            </asp:BoundColumn>
 
         </Columns> 
 
      </asp:DataGrid>

      <hr>

      <table cellpadding="5">

         <tr>

            <td>

               Item BackColor:

            </td>

            <td>

               Alternating item BackColor:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ItemBackColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True"
 Value="White"> White </asp:ListItem>
                  <asp:ListItem Value="Silver">
 Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray">
 Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki">
 Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki">
 Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

            <td>

               <asp:DropDownList id="AltItemBackColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True"
 Value="White"> White </asp:ListItem>
                  <asp:ListItem Value="Silver">
 Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray">
 Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki">
 Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki">
 Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
 
   </form>
 
</body>
</html>

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <script runat="server">
 
      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataGrid 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)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 5; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
 
            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) 
         {
            ItemsGrid.DataSource = CreateDataSource();
            ItemsGrid.DataBind();
         }

      }

      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the background color for the items and alternating items
 in
         // the DataGrid control. Notice that the ItemStyle property
 affects
         // the even-numbered items, while the AlternatingItemStyle
 property 
         // affects the odd-numbered items.
         ItemsGrid.ItemStyle.BackColor = 
             System.Drawing.Color.FromName(ItemBackColorList.SelectedItem.Value);
         ItemsGrid.AlternatingItemStyle.BackColor = 
             System.Drawing.Color.FromName(AltItemBackColorList.SelectedItem.Value);

      }

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGrid ItemStyle and AlternatingItemStyle Example</h3>

      Select background colors for the items and alternating items.

      <br><br>
 
      <b>Product List</b>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="False"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <ItemStyle BackColor="White">
         </ItemStyle>

         <AlternatingItemStyle BackColor="White">
         </AlternatingItemStyle>

         <Columns>

            <asp:BoundColumn DataField="IntegerValue" 
                 HeaderText="Item"/>

            <asp:BoundColumn DataField="StringValue" 
                 HeaderText="Description"/>

            <asp:BoundColumn DataField="CurrencyValue" 
                 HeaderText="Price"
                 DataFormatString="{0:c}">

               <ItemStyle HorizontalAlign="Right">
               </ItemStyle>

            </asp:BoundColumn>
 
         </Columns> 
 
      </asp:DataGrid>

      <hr>

      <table cellpadding="5">

         <tr>

            <td>

               Item BackColor:

            </td>

            <td>

               Alternating item BackColor:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ItemBackColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True" Value="White">
 White </asp:ListItem>
                  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

            <td>

               <asp:DropDownList id="AltItemBackColorList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem Selected="True" Value="White">
 White </asp:ListItem>
                  <asp:ListItem Value="Silver"> Silver </asp:ListItem>
                  <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
                  <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
                  <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
 
   </form>
 
</body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGrid クラス
DataGrid メンバ
System.Web.UI.WebControls 名前空間
DataGrid.AlternatingItemStyle プロパティ
TableItemStyle
Style


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

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

辞書ショートカット

すべての辞書の索引

「DataGrid.ItemStyle プロパティ」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS