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

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

DataGridColumn.HeaderImageUrl プロパティ

列のヘッダー セクション表示するイメージ位置取得または設定します

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

Public Overridable Property
 HeaderImageUrl As String
Dim instance As DataGridColumn
Dim value As String

value = instance.HeaderImageUrl

instance.HeaderImageUrl = value
public virtual string HeaderImageUrl { get;
 set; }
/** @property */
public String get_HeaderImageUrl ()

/** @property */
public void set_HeaderImageUrl (String value)
public function get HeaderImageUrl
 () : String

public function set HeaderImageUrl
 (value : String)

プロパティ
列のヘッダー セクション表示するイメージ位置既定値は String.Empty です。

解説解説
使用例使用例

HeaderImageUrl プロパティ使用して、列のヘッダー セクション表示するイメージ指定する方法次のコード例示します

<%@ 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)))
         dt.Columns.Add(new DataColumn("BooleanValue",
 GetType(Boolean)))
 
         ' 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)
            dr(3) = False
 
            dt.Rows.Add(dr)
         
         Next i

         ' To persist the data source between posts to the server, store
         ' it in session state.  
         Session("Source") = dt
 
         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
 
         
            ' Make sure to set the header text before binding the data
 to 
            ' the DataGrid control; otherwise, the change will not appear
 
            ' until the next time the page is refreshed.
            ItemsGrid.Columns(0).HeaderText = "Item"

            ItemsGrid.DataSource = CreateDataSource()
            ItemsGrid.DataBind()
        
         End If

      End Sub

      Sub Button_Click(sender As Object,
 e As EventArgs) 

         Dim subtotal As Double
 = 0.0

         ' Update the data source with the user's selection and 
         ' calculate the subtotal.
         Dim dt As DataTable = UpdateSource(subtotal)

         ' Display the subtotal in the footer section of the third column.
         ItemsGrid.Columns(2).FooterText = "Subtotal: "
 & subtotal.ToString("c")

         ' Create a DataView and bind it to the DataGrid control.
         Dim dv As DataView = New
 DataView(dt)
         ItemsGrid.DataSource = dv
         ItemsGrid.DataBind()

      End Sub

      ' This version of UpdateSource updates the data source and 
      ' calculates the subtotal.
      Function UpdateSource(ByRef subtotal
 As Double) As DataTable
 

         ' Retrieve the data table from session state.
         Dim dt As DataTable = CType(Session("Source"),
 DataTable)
         Dim item As DataGridItem 

         ' Iterate through the Items collection and update the data
 source
         ' with the user's selections. If an item is selected, add the
         ' amount of the item to the subtotal.
         For Each item in
 ItemsGrid.Items

            ' Retrieve the SelectCheckBox CheckBox control from the
 
            ' specified item (row) in the DataGrid control.
            Dim selection As CheckBox = CType(item.FindControl("SelectCheckBox"),
 CheckBox)

            If Not selection Is
 Nothing

               ' Update the BooleanValue field with the value of the
 check box.
               dt.Rows(item.ItemIndex)(3) = selection.Checked

               ' Add the value of the item to the subtotal if the item
 is 
               ' selected.
               If selection.Checked Then
           
                  subtotal += Convert.ToDouble(item.Cells(2).Text.Substring(1))

               End If

            End If

         Next

         ' Save the data source.
         Session("Source") = dt

         Return dt

      End Function

      ' This version of UpdateSource updates the data source only.
      Function UpdateSource() As DataTable
 

         ' Retrieve the data table from session state.
         Dim dt As DataTable = CType(Session("Source"),
 DataTable)
         Dim item As DataGridItem 

         ' Iterate through the Items collection and update the data
 source
         ' with the user's selections. If an item is selected, add the
         ' amount of the item to the subtotal.
         For Each item in
 ItemsGrid.Items

            ' Retrieve the SelectCheckBox CheckBox control from the
  
            ' specified item (row) in the DataGrid control.
            Dim selection As CheckBox = _
                CType(item.FindControl("SelectCheckBox"),
 CheckBox)

            If Not selection Is
 Nothing

               ' Update the BooleanValue field with the value of the
 check box.
               dt.Rows(item.ItemIndex)(3) = selection.Checked

            End If

         Next

         ' Save the data source.
         Session("Source") = dt

         Return dt

      End Function

      Sub Selection_Change(sender As Object,
 e As EventArgs)

         ' Set the image for the header section of the first column
 in
         ' the DataGrid control.
         ItemsGrid.Columns(0).HeaderImageUrl = List.SelectedItem.Value

         ' Create a DataView and bind it to the DataGrid control. This
 
         ' will refresh the DataGrid control with the updated header
 image.
         Dim dv As DataView = New
 DataView(UpdateSource())
         ItemsGrid.DataSource = dv
         ItemsGrid.DataBind()

      End Sub

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGridColumn HeaderImageUrl Example</h3>

      Select an image for the header section
 of the first column.

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

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

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

         <Columns>

            <asp:BoundColumn DataField="IntegerValue"
                 HeaderImageUrl="image1.jpg"/>

            <asp:BoundColumn DataField="StringValue"
                 HeaderImageUrl="image2.jpg"/>

            <asp:BoundColumn DataField="CurrencyValue"
 
                 DataFormatString="{0:c}"
                 HeaderImageUrl="image3.jpg">

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

            </asp:BoundColumn>

            <asp:TemplateColumn
                 HeaderImageUrl="image4.jpg">

               <ItemTemplate>

                  <asp:CheckBox id="SelectCheckBox"
                       Text="Add to Cart"
                       Checked='<%# DataBinder.Eval(Container.DataItem,
 "BooleanValue") %>'
                       runat="server"/>

               </ItemTemplate>

            </asp:TemplateColumn>
 
         </Columns> 
 
      </asp:DataGrid>

      <br><br>

      <asp:Button id="SubmitButton"
           Text="Submit"
           OnClick = "Button_Click"
           runat="server"/>
       
      <hr>

      Header image for first column: <br> 

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

         <asp:ListItem Selected="True" Value="image1.jpg">
 Image 1 </asp:ListItem>
         <asp:ListItem Value="image2.jpg"> Image
 2 </asp:ListItem>
         <asp:ListItem Value="image3.jpg"> Image
 3 </asp:ListItem>
         <asp:ListItem Value="image4.jpg"> Image
 4 </asp:ListItem>

      </asp:DropDownList>
 
   </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)));
         dt.Columns.Add(new DataColumn("BooleanValue",
 typeof(bool)));
 
         // 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);
            dr[3] = false;
 
            dt.Rows.Add(dr);
         }

         // To persist the data source between posts to the server,
 store
         // it in session state.  
         Session["Source"] = dt;
 
         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) 
         {
            // Make sure to set the header text before binding the data
 to 
            // the DataGrid control; otherwise, the change will not
 appear 
            // until the next time the page is refreshed.
            ItemsGrid.Columns[0].HeaderText = "Item";

            ItemsGrid.DataSource = CreateDataSource();
            ItemsGrid.DataBind();
         }

      }

      void Button_Click(Object sender, EventArgs e) 
      {

         double subtotal = 0.0;

         // Update the data source with the user's selection and 
         // calculate the subtotal.
         DataTable dt = UpdateSource(ref subtotal);

         // Display the subtotal in the footer section of the third
 column.
         ItemsGrid.Columns[2].FooterText = 
             "Subtotal: " + subtotal.ToString("c");

         // Create a DataView and bind it to the DataGrid control.
         DataView dv = new DataView(dt);
         ItemsGrid.DataSource = dv;
         ItemsGrid.DataBind();

      }

      // This version of UpdateSource updates the data source and 
      // calculates the subtotal.
      DataTable UpdateSource(ref double subtotal)
      {

         // Retrieve the data table from session state.
         DataTable dt = (DataTable)Session["Source"];

         // Iterate through the Items collection and update the data
 source
         // with the user's selections. If an item is selected, add
 the
         // amount of the item to the subtotal.
         foreach (DataGridItem item in ItemsGrid.Items)
         {

            // Retrieve the SelectCheckBox CheckBox control from the
 
            // specified item (row) in the DataGrid control.
            CheckBox selection = (CheckBox)item.FindControl("SelectCheckBox");

            if (selection != null)
            {

               // Update the BooleanValue field with the value of the
 check box.
               dt.Rows[item.ItemIndex][3] = selection.Checked;

               // Add the value of the item to the subtotal if the item
 is
               // selected.
               if (selection.Checked)
               {
                  subtotal += 
                      Convert.ToDouble(item.Cells[2].Text.Substring(1));
               }

            }

         }

         // Save the data source.
         Session["Source"] = dt;

         return dt;

      }

      // This version of UpdateSource updates the data source only.
      DataTable UpdateSource()
      {

         // Retrieve the data table from session state.
         DataTable dt = (DataTable)Session["Source"];

         // Iterate through the Items collection and update the data
 source
         // with the user's selections. If an item is selected, add
 the
         // amount of the item to the subtotal.
         foreach (DataGridItem item in ItemsGrid.Items)
         {

            // Retrieve the SelectCheckBox CheckBox control from the
 
            // specified item (row) in the DataGrid control.
            CheckBox selection = (CheckBox)item.FindControl("SelectCheckBox");

            if (selection != null)
            {

               // Update the BooleanValue field with the value of the
 check box.
               dt.Rows[item.ItemIndex][3] = selection.Checked;

            }

         }

         // Save the data source.
         Session["Source"] = dt;

         return dt;

      }

      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the image for the header section of the first column
 in
         // the DataGrid control.
         ItemsGrid.Columns[0].HeaderImageUrl = List.SelectedItem.Value;

         // Create a DataView and bind it to the DataGrid control. This
 
         // will refresh the DataGrid control with the updated header
 image.
         DataView dv = new DataView(UpdateSource());
         ItemsGrid.DataSource = dv;
         ItemsGrid.DataBind();

      }

   </script>
 
<body>
 
   <form runat=server>
 
      <h3>DataGridColumn HeaderImageUrl Example</h3>

      Select an image for the header section of the first column.

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

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

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

         <Columns>

            <asp:BoundColumn DataField="IntegerValue"
                 HeaderImageUrl="image1.jpg"/>

            <asp:BoundColumn DataField="StringValue"
                 HeaderImageUrl="image2.jpg"/>

            <asp:BoundColumn DataField="CurrencyValue" 
                 DataFormatString="{0:c}"
                 HeaderImageUrl="image3.jpg">

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

            </asp:BoundColumn>

            <asp:TemplateColumn
                 HeaderImageUrl="image4.jpg">

               <ItemTemplate>

                  <asp:CheckBox id="SelectCheckBox"
                       Text="Add to Cart"
                       Checked='<%# DataBinder.Eval(Container.DataItem, "BooleanValue")
 %>'
                       runat="server"/>

               </ItemTemplate>

            </asp:TemplateColumn>
 
         </Columns> 
 
      </asp:DataGrid>

      <br><br>

      <asp:Button id="SubmitButton"
           Text="Submit"
           OnClick = "Button_Click"
           runat="server"/>
       
      <hr>

      Header image for first column: <br> 

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

         <asp:ListItem Selected="True" Value="image1.jpg">
 Image 1 </asp:ListItem>
         <asp:ListItem Value="image2.jpg"> Image 2 </asp:ListItem>
         <asp:ListItem Value="image3.jpg"> Image 3 </asp:ListItem>
         <asp:ListItem Value="image4.jpg"> Image 4 </asp:ListItem>

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridColumn クラス
DataGridColumn メンバ
System.Web.UI.WebControls 名前空間
String.Empty


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

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

辞書ショートカット

すべての辞書の索引

「DataGridColumn.HeaderImageUrl プロパティ」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS