DetailsViewRow クラスとは? わかりやすく解説

DetailsViewRow クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

DetailsView コントロール内の行を表します

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

Public Class DetailsViewRow
    Inherits TableRow
Dim instance As DetailsViewRow
public class DetailsViewRow : TableRow
public ref class DetailsViewRow : public
 TableRow
public class DetailsViewRow extends TableRow
public class DetailsViewRow extends
 TableRow
解説解説

DetailsViewRow クラスは、DetailsView コントロール個別の行を表すために使用されます。DetailsView コントロール各行には、行の種類指定されています。DetailsView コントロール有効な行の種類次の表に示します

行の種類

説明

DataRow

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

EmptyDataRow

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

Footer

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

Header

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

Pager

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

DetailsViewRow オブジェクトの行の種類確認するには、RowType プロパティ使用しますDetailsViewRow オブジェクトには、状態も関連付けられます。状態は、次の表に示す値のビットごとの組み合わせなります

状態の値

説明

Alternate

DetailsViewRow オブジェクトDetailsView コントロール代替行です。

Edit

DetailsViewRow オブジェクト編集モードです。

Insert

DetailsViewRow オブジェクト挿入モードです。

Normal

DetailsViewRow オブジェクト標準 (既定) の状態です。

DetailsViewRow オブジェクトの状態を確認するには、RowState プロパティ使用します

DetailsView コントロールは、そのすべてのデータ行を Rows コレクション格納しますRows コレクション内の DetailsViewRow オブジェクトインデックス確認するには、RowIndex プロパティ使用します

Cells プロパティ使用してDetailsViewRow オブジェクト個別セルアクセスできますセルコントロール格納されている場合は、セルControls コレクション使用してセルからコントロール取得できますコントロールID プロパティ指定されている場合は、セルの FindControl メソッド使用してコントロール検索することもできます

BoundField フィールドの列、または自動的に生成されフィールドの列からフィールド値を取得するには、セルText プロパティ使用しますフィールド値がコントロールバインドされている、その他の種類フィールドの列からフィールド値を取得するには、最初に適切なセルからコントロール取得し次にコントロール適切なプロパティアクセスます。

DetailsViewRow クラスインスタンス初期プロパティ値の一覧については、DetailsViewRow コンストラクタトピック参照してください

使用例使用例

フィールド値を DetailsViewRow オブジェクトから取得する方法コード例次に示します

<%@ page language="VB" %>

<script runat="server">

  Sub SubmitButton_Click(ByVal sender As
 Object, ByVal e As EventArgs)
 
    ' Use the Count property to determine whether the
    ' Rows collection contains any item.
    If ItemDetailsView.Rows.Count > 0 Then
    
      ' Iterate through the Rows collection and display
      ' the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>"
    
      Dim row As DetailsViewRow
    
      For Each row In ItemDetailsView.Rows

        ' Use the Text property to access the value of 
        ' each cell. In this example, the cells in the 
        ' first column (index 0) contains the field names, 
        ' while the cells in the second column (index 1)
        ' contains the field value. 
        MessageLabel.Text &= row.Cells(0).Text & " = "
 & _
          row.Cells(1).Text & "<br/>"
    
      Next
    
    Else
      
      MessageLabel.Text = "No items."
    
    End If
    
  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewRow Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
      </asp:detailsview>
      
      <br/>
      
      <asp:button id="SubmitButton" 
        text="Display Row Values"
        onclick="SubmitButton_Click"
        runat="server"/>
        
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>
      
      <!-- This example uses Microsoft SQL Server and connects
  -->
      <!-- to the Northwind sample database. Use an ASP.NET
     -->
      <!-- expression to retrieve the connection string
 value   -->
      <!-- from the web.config file.                            -->
      <asp:sqldatasource id="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>  
  
    </form>
  </body>
</html>
<%@ page language="C#" %>

<script runat="server">

  void SubmitButton_Click(Object sender, EventArgs e)
  {

    // Use the Count property to determine whether the
    // Rows collection contains any item.
    if (ItemDetailsView.Rows.Count > 0)
    {
      // Iterate through the Rows collection and display
      // the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>";

      foreach (DetailsViewRow row in ItemDetailsView.Rows)
      {
        // Use the Text property to access the value of 
        // each cell. In this example, the cells in the 
        // first column (index 0) contains the field names, 
        // while the cells in the second column (index 1)
        // contains the field value. 
        MessageLabel.Text += row.Cells[0].Text + " = " +
          row.Cells[1].Text + "<br/>";
      }
    }
    else
    {
      MessageLabel.Text = "No items.";
    }

  }
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewRow Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
      </asp:detailsview>
      
      <br/>
      
      <asp:button id="SubmitButton" 
        text="Display Row Values"
        onclick="SubmitButton_Click"
        runat="server"/>
        
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>
      
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value
   -->
      <!-- from the web.config file.                            -->
      <asp:sqldatasource id="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </form>
  </body>
</html>

ヘッダー行を表す DetailsViewRow オブジェクトから Image コントロール取得する方法コード例次に示しますImage コントロールヘッダー テンプレート宣言されます。

<%@ page language="VB" %>

<script runat="server">

  Sub ItemDetailsView_ItemCreated(ByVal sender
 As Object, ByVal e As
 EventArgs)
  
    ' Retrieve the header row. 
    Dim headerRow As DetailsViewRow = ItemDetailsView.HeaderRow
    
    ' Retrieve the Image control from the header row.
    Dim logoImage As Image = CType(headerRow.FindControl("LogoImage"),
 Image)

    ' Display a custom image to indicate whether the 
    ' DetailsView control is in edit or read-only mode.
    Select Case ItemDetailsView.CurrentMode

      Case DetailsViewMode.Edit
        logoImage.ImageUrl = "~/Images/Edit.jpg"

      Case DetailsViewMode.ReadOnly
        logoImage.ImageUrl = "~/Images/ReadOnly.jpg"

      Case Else
        logoImage.ImageUrl = "~/Images/Default.jpg"

    End Select

  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewRow Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false"
        autogenerateeditbutton="true"
        datakeynames="CustomerID"  
        onitemcreated="ItemDetailsView_ItemCreated"
  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
        
        <headertemplate>
          <asp:image id="LogoImage"
            imageurl="~/Images/Default.jpg" 
            runat="server"/>
        </headertemplate>
      </asp:detailsview>
      
      <!-- This example uses Microsoft SQL Server and connects
  -->
      <!-- to the Northwind sample database. Use an ASP.NET
     -->
      <!-- expression to retrieve the connection string
 value   -->
      <!-- from the web.config file.                            -->
      <asp:sqldatasource id="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>  
  
    </form>
  </body>
</html>
<%@ page language="C#" %>

<script runat="server">

  void ItemDetailsView_ItemCreated(Object sender, EventArgs e)
  {
    // Retrieve the header row. 
    DetailsViewRow headerRow = ItemDetailsView.HeaderRow;
    
    // Retrieve the Image control from the header row.
    Image logoImage = (Image)headerRow.FindControl("LogoImage");

    // Display a custom image to indicate whether the 
    // DetailsView control is in edit or read-only mode.
    switch (ItemDetailsView.CurrentMode)
    {
      case DetailsViewMode.Edit:
        logoImage.ImageUrl = "~/Images/Edit.jpg";
        break;
      case DetailsViewMode.ReadOnly:
        logoImage.ImageUrl = "~/Images/ReadOnly.jpg";
        break;
      default:
        logoImage.ImageUrl = "~/Images/Default.jpg";
        break;
    }

  }
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewRow Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false"
        autogenerateeditbutton="true"
        datakeynames="CustomerID"  
        onitemcreated="ItemDetailsView_ItemCreated"  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
        
        <headertemplate>
          <asp:image id="LogoImage"
            imageurl="~/Images/Default.jpg" 
            runat="server"/>
        </headertemplate>
      </asp:detailsview>
      
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value
   -->
      <!-- from the web.config file.                            -->
      <asp:sqldatasource id="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update [Customers] Set 
          [CompanyName]=@CompanyName, [Address]=@Address, 
          [City]=@City, [PostalCode]=@PostalCode, 
          [Country]=@Country 
          Where [CustomerID]=@CustomerID"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </form>
  </body>
</html>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.TableRow
        System.Web.UI.WebControls.DetailsViewRow
           System.Web.UI.WebControls.DetailsViewPagerRow
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsViewRow メンバ
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewRowCollection
DetailsView.Rows プロパティ
DataBoundLiteralControl
TableCell
Controls
FindControl
TableRow
Cells
RowIndex
RowState
RowType



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

辞書ショートカット

すべての辞書の索引

「DetailsViewRow クラス」の関連用語

DetailsViewRow クラスのお隣キーワード
検索ランキング

   

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



DetailsViewRow クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS