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

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

GridViewRow.RowType プロパティ

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

GridViewRow オブジェクトの行の種類取得します

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

Public Overridable Property
 RowType As DataControlRowType
Dim instance As GridViewRow
Dim value As DataControlRowType

value = instance.RowType

instance.RowType = value
public virtual DataControlRowType RowType { get;
 set; }
public:
virtual property DataControlRowType RowType {
    DataControlRowType get ();
    void set (DataControlRowType value);
}
/** @property */
public DataControlRowType get_RowType ()

/** @property */
public void set_RowType (DataControlRowType
 value)
public function get RowType
 () : DataControlRowType

public function set RowType
 (value : DataControlRowType)

プロパティ
DataControlRowType 値の 1 つ

解説解説

RowType プロパティ使用してGridViewRow オブジェクトが表す行の種類確認しますさまざまな行の種類の値の一覧を次の表に示します

行の種類

説明

DataRow

GridView コントロールデータ行。

Footer

GridView コントロールフッター行。

Header

GridView コントロールヘッダー行。

EmptyDataRow

GridView コントロールの空の行。空の行は、GridView コントロール表示するレコードない場合表示されます。

Pager

GridView コントロールページ行。

Separator

GridView コントロール区切り行。

このプロパティは、通常操作実行前に行の種類確認するために使用されます。

使用例使用例

RowType プロパティ使用して作成される行がフッター行であるかどうか確認する方法次の例に示します。行がフッター行の場合、列の合計値フッター行で更新されます。

<%@ Page language="VB" %>

<script runat="server">
  
  ' Create a variable to store the order total.
  Private orderTotal As Decimal
 = 0.0

  Sub OrderGridView_RowCreated(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)
    
    ' Retrieve the current row.
    Dim row As GridViewRow = e.Row
    
    ' Update the column total if the row being created is
    ' a footer row.
    If row.RowType = DataControlRowType.Footer Then
          
      ' Get the OrderTotalTotal Label control in the footer row.
      Dim total As Label = CType(e.Row.FindControl("OrderTotalLabel"),
 Label)
      
      ' Display the grand total of the order formatted as currency.
      If (Not total Is Nothing)
      
        total.Text = orderTotal.ToString("c")
      
      End If 
      
    End If
    
  End Sub
  
  Sub OrderGridView_RowDataBound(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)
    
    ' Retrieve the current row.
    Dim row As GridViewRow = e.Row
    
    ' Add the field value to the column total if the row being created
 is
    ' a data row.
    If row.RowType = DataControlRowType.DataRow Then
      
      ' Get the cell that contains the item total.
      Dim cell As TableCell = e.Row.Cells(2)
      
      ' Get the DataBoundLiteralControl control that contains the 
      ' data bound value.
      Dim boundControl As DataBoundLiteralControl
 = CType(cell.Controls(0), DataBoundLiteralControl)
      
      ' Remove the '$' character for the type converter to work properly.
      Dim itemTotal As String
 = boundControl.Text.Replace("$",  "")
      
      ' Add the total for an item (row) to the order total.
      orderTotal += Convert.ToDecimal(itemTotal)
      
    End If
    
  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRow RowType 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="OrderGridView" 
        datasourceid="OrderSqlDataSource" 
        autogeneratecolumns="False" 
        showfooter="true"
        onrowcreated="OrderGridView_RowCreated"
        onrowdatabound="OrderGridView_RowDataBound"
   
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="UnitPrice"
            itemstyle-horizontalalign="Right"
            headertext="Unit Price" 
            dataformatstring="{0:c}"/>
                  
          <asp:boundfield datafield="Quantity"
            itemstyle-horizontalalign="Right"
            headertext="Quantity"/>
                           
          <asp:templatefield headertext="Total"
            itemstyle-horizontalalign="Right"
            footerstyle-horizontalalign="Right"
            footerstyle-backcolor="Blue"
            footerstyle-forecolor="White">
            <itemtemplate>
              <%#Eval("Total", "{0:c}")
 %>
            </itemtemplate>
            <footertemplate>
              <asp:label id="OrderTotalLabel"
                runat="server"/>
            </footertemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Northwind sample database.              
     -->
      <asp:sqldatasource id="OrderSqlDataSource"
  
        selectcommand="SELECT [OrderID], [UnitPrice], [Quantity],
 [UnitPrice]*[Quantity] As [Total] FROM [order details] WHERE [OrderID]=10248"
        connectionstring="server=localhost;database=northwind;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

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

<script runat="server">
  
  // Create a variable to store the order total.
  private Decimal orderTotal = 0.0M;

  void OrderGridView_RowCreated(Object sender, GridViewRowEventArgs
 e)
  {
    
    // Retrieve the current row. 
    GridViewRow row = e.Row;
    
    // Update the column total if the row being created is
    // a footer row.
    if (row.RowType == DataControlRowType.Footer)
    {
      
      // Get the OrderTotalTotal Label control in the footer row.
      Label total = (Label)e.Row.FindControl("OrderTotalLabel");
      
      // Display the grand total of the order formatted as currency.
      if (total != null)
      {
        total.Text = orderTotal.ToString("c");
      }
      
    }
    
  }
  
  void OrderGridView_RowDataBound(Object sender, GridViewRowEventArgs
 e)
  {
   
    // Retrieve the current row. 
    GridViewRow row = e.Row;
    
    // Add the field value to the column total if the row being created
 is
    // a data row. 
    if (row.RowType == DataControlRowType.DataRow)
    {
      
      // Get the cell that contains the item total.
      TableCell cell = e.Row.Cells[2];
      
      // Get the DataBoundLiteralControl control that contains the 
      // data bound value.
      DataBoundLiteralControl boundControl = (DataBoundLiteralControl)cell.Controls[0];
      
      // Remove the '$' character for the type converter to work properly.
      String itemTotal = boundControl.Text.Replace("$",  "");
      
      // Add the total for an item (row) to the order total.
      orderTotal += Convert.ToDecimal(itemTotal);
      
    }
    
  }
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRow RowType 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="OrderGridView" 
        datasourceid="OrderSqlDataSource" 
        autogeneratecolumns="False" 
        showfooter="true"
        onrowcreated="OrderGridView_RowCreated"
        onrowdatabound="OrderGridView_RowDataBound"   
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="UnitPrice"
            itemstyle-horizontalalign="Right"
            headertext="Unit Price" 
            dataformatstring="{0:c}"/>
                  
          <asp:boundfield datafield="Quantity"
            itemstyle-horizontalalign="Right"
            headertext="Quantity"/>
                           
          <asp:templatefield headertext="Total"
            itemstyle-horizontalalign="Right"
            footerstyle-horizontalalign="Right"
            footerstyle-backcolor="Blue"
            footerstyle-forecolor="White">
            <itemtemplate>
              <%#Eval("Total", "{0:c}") %>
            </itemtemplate>
            <footertemplate>
              <asp:label id="OrderTotalLabel"
                runat="server"/>
            </footertemplate>
          </asp:templatefield>
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrderSqlDataSource"  
        selectcommand="SELECT [OrderID], [UnitPrice], [Quantity], [UnitPrice]*[Quantity]
 As [Total] FROM [order details] WHERE [OrderID]=10248"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewRow クラス
GridViewRow メンバ
System.Web.UI.WebControls 名前空間
DataControlRowType 列挙
DataControlRowState 列挙
GridViewRow.RowState プロパティ



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

辞書ショートカット

すべての辞書の索引

「GridViewRow.RowType プロパティ」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS