GridViewRow イベント

名前 | 説明 | |
---|---|---|
![]() | DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。 ( Control から継承されます。) |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 ( Control から継承されます。) |
![]() | Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。 ( Control から継承されます。) |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 ( Control から継承されます。) |
![]() | PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。 ( Control から継承されます。) |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。 ( Control から継承されます。) |

関連項目
GridViewRow クラスSystem.Web.UI.WebControls 名前空間
GridView クラス
GridViewRowCollection
GridView.Rows プロパティ
DataBoundLiteralControl
TableCell
Controls
FindControl
TableRow
Cells
GridViewRow.DataItem プロパティ
GridViewRow.DataItemIndex プロパティ
GridViewRow.RowIndex プロパティ
GridViewRow.RowState プロパティ
GridViewRow.RowType プロパティ
GridViewRow クラス
アセンブリ: System.Web (system.web.dll 内)


GridViewRow クラスは、GridView コントロールの個別の行を表すために使用されます。GridView コントロールの各行には、行の種類が指定されています。さまざまな行の種類の一覧を次の表に示します。
行の種類 | |
---|---|
DataGridRowType.DataRow | |
DataGridRowType.Footer | |
DataGridRowType.Header | |
DataGridRowType.NullRow | GridView コントロールの null 行。null 行は、表示するレコードがない場合に GridView コントロールに表示されます。 |
DataGridRowType.Pager | |
DataGridRowType.Separator |
GridViewRow オブジェクトの行の種類を確認するには、RowType プロパティを使用します。GridViewRow オブジェクトには、状態も関連付けられます。状態は、次の表に示す値のビットごとの組み合わせになります。
状態の値 | |
---|---|
DataControlRowState.Alternate | |
DataControlRowState.Edit | |
DataControlRowState.Normal | |
DataControlRowState.Selected |
GridViewRow オブジェクトの状態を確認するには、RowState プロパティを使用します。
GridView コントロールは、すべてのデータ行を Rows コレクションに格納します。Rows コレクション内の GridViewRow オブジェクトのインデックスを確認するには、RowIndex プロパティを使用します。
DataItem プロパティを使用して、GridViewRow オブジェクトにバインドされている基になるデータ オブジェクトのプロパティにアクセスできます。
基になるデータ ソースのデータ オブジェクトのインデックスを確認するには、DataItemIndex プロパティを使用します。
Cells プロパティを使用して、GridViewRow オブジェクトの個別のセルにアクセスできます。セルに他のコントロールが格納されている場合は、セルの Controls コレクションを使用して、セルからコントロールを取得できます。コントロールに ID が指定されている場合は、セルの FindControl メソッドを使用してコントロールを検索することもできます。
BoundField フィールド列または自動生成されたフィールド列からフィールド値を取得するには、セルの Text プロパティを使用します。フィールド値がコントロールにバインドされている他の種類のフィールド列からフィールド値を取得するには、該当するセルからコントロールを取得してから、コントロールの該当するプロパティにアクセスします。
![]() |
---|
値をコントロールのプロパティにバインドせずに、直接 TemplateField フィールド列にデータ バインディング式を使用することもできます。この場合、自動的にフィールド値が DataBoundLiteralControl コントロールに配置されます。フィールド値を取得するには、該当するセルから DataBoundLiteralControl コントロールを取得してから Text プロパティを使用する必要があります。 |
GridViewRow のインスタンスの初期プロパティ値の一覧については、GridViewRow コンストラクタのトピックを参照してください。

GridViewRow オブジェクトを使用して、GridView コントロールのセルからフィールド値を取得し、その値をページに表示する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub AuthorsGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) ' Get the selected row from the GridView control. Dim selectRow As GridViewRow = AuthorsGridView.SelectedRow ' Get the author's first and last name from the appropriate ' cells in the selected row. For BoundField field columns ' and automatically generated field columns, the Text property ' of a cell is used to access a field value. Dim lastName As String = selectRow.Cells(1).Text ' In a TemplateField column where a data-binding expression ' is used directly in the ItemTemplate, the field value ' is automatically placed in DataBoundLiteral control. ' Retrieve the DataBoundLiteral control from the cell. The ' DataBoundLiteral control is the first control in the ' Controls collection. Dim firstNameLiteral As DataBoundLiteralControl = CType(selectRow.Cells(2).Controls(0), DataBoundLiteralControl) Dim firstName As String = firstNameLiteral.Text ' Display the name of the selected author. Message.Text = "You selected " & firstName & " " & lastName & "." End Sub </script> <html> <body> <form runat="server"> <h3>GridViewRow Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" autogenerateselectbutton="true" onselectedindexchanged="AuthorsGridView_SelectedIndexChanged" runat="server"> <columns> <asp:boundfield datafield="au_lname" headertext="Last Name"/> <asp:templatefield headertext="FirstName"> <itemtemplate> <%#Eval("au_fname")%> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void AuthorsGridView_SelectedIndexChanged(Object sender, EventArgs e) { // Get the selected row from the GridView control. GridViewRow selectRow = AuthorsGridView.SelectedRow; // Get the author's first and last name from the appropriate // cells in the selected row. For BoundField field columns // and automatically generated field columns, the Text property // of a cell is used to access a field value. String lastName = selectRow.Cells[1].Text; // In a TemplateField column where a data-binding expression // is used directly in the ItemTemplate, the field value // is automatically placed in DataBoundLiteral control. // Retrieve the DataBoundLiteral control from the cell. The // DataBoundLiteral control is the first control in the // Controls collection. DataBoundLiteralControl firstNameLiteral = (DataBoundLiteralControl)selectRow.Cells[2].Controls[0]; String firstName = firstNameLiteral.Text; // Display the name of the selected author. Message.Text = "You selected " + firstName + " " + lastName + "."; } </script> <html> <body> <form runat="server"> <h3>GridViewRow Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" autogenerateselectbutton="true" onselectedindexchanged="AuthorsGridView_SelectedIndexChanged" runat="server"> <columns> <asp:boundfield datafield="au_lname" headertext="Last Name"/> <asp:templatefield headertext="FirstName"> <itemtemplate> <%#Eval("au_fname")%> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
GridViewRow オブジェクトを使用して、TemplateField フィールド列の項目編集テンプレートで宣言されている TextBox コントロールを取得する方法を次の例に示します。その後、データ ソースを更新するために、テキスト ボックスの値が SqlDataSource コントロールに渡されます。
<%@ Page language="VB" %> <script runat="server"> Sub AuthorsGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) ' The GridView control does not automatically extract updated values ' from TemplateField column fields. These values must be added manually ' to the NewValues dictionary. ' Get the GridViewRow object that represents the row being edited ' from the Rows collection of the GridView control. Dim index As Integer = AuthorsGridView.EditIndex Dim row As GridViewRow = AuthorsGridView.Rows(index) ' Get the controls that contain the updated values. In this ' example, the updated values are contained in the TextBox ' controls declared in the EditItemTemplates of the TemplateField ' column fields in the GridView control. Dim lastName As TextBox = CType(row.FindControl("LastNameTextBox"), TextBox) Dim firstName As TextBox = CType(row.FindControl("FirstNameTextBox"), TextBox) ' Add the updated values to the NewValues dictionary. Use the ' parameter names declared in the parameterized update query ' string for the key names. e.NewValues("au_lname") = lastName.Text e.NewValues("au_fname") = firstName.Text End Sub </script> <html> <body> <form runat="server"> <h3>GridViewRow Example</h3> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames attribute as read-only --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" datakeynames="au_id" cellpadding="10" onrowupdating="AuthorsGridView_RowUpdating" runat="server"> <columns> <asp:boundfield datafield="au_id" headertext="Author ID" readonly="true"/> <asp:templatefield headertext="Last Name" itemstyle-verticalalign="Top"> <itemtemplate> <%#Eval("au_lname")%> </itemtemplate> <edititemtemplate> <asp:textbox id="LastNameTextBox" text='<%#Eval("au_lname")%>' width="90" runat="server"/> <br/> <asp:requiredfieldvalidator id="LastNameRequiredValidator" controltovalidate="LastNameTextBox" display="Dynamic" text="Please enter a last name." runat="server" /> </edititemtemplate> </asp:templatefield> <asp:templatefield headertext="First Name" itemstyle-verticalalign="Top"> <itemtemplate> <%#Eval("au_fname")%> </itemtemplate> <edititemtemplate> <asp:textbox id="FirstNameTextBox" text='<%#Eval("au_fname")%>' width="90" runat="server"/> <br/> <asp:requiredfieldvalidator id="FirstNameRequiredValidator" controltovalidate="FirstNameTextBox" display="Dynamic" text="Please enter a first name." runat="server" /> </edititemtemplate> </asp:templatefield> <asp:checkboxfield datafield="contract" headertext="Contract" readonly="true"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]" updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs e) { // The GridView control does not automatically extract updated values // from TemplateField column fields. These values must be added manually // to the NewValues dictionary. // Get the GridViewRow object that represents the row being edited // from the Rows collection of the GridView control. int index = AuthorsGridView.EditIndex; GridViewRow row = AuthorsGridView.Rows[index]; // Get the controls that contain the updated values. In this // example, the updated values are contained in the TextBox // controls declared in the EditItemTemplates of the TemplateField // column fields in the GridView control. TextBox lastName = (TextBox)row.FindControl("LastNameTextBox"); TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox"); // Add the updated values to the NewValues dictionary. Use the // parameter names declared in the parameterized update query // string for the key names. e.NewValues["au_lname"] = lastName.Text; e.NewValues["au_fname"] = firstName.Text; } </script> <html> <body> <form runat="server"> <h3>GridViewRow Example</h3> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames attribute as read-only --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" autogenerateeditbutton="true" datakeynames="au_id" cellpadding="10" onrowupdating="AuthorsGridView_RowUpdating" runat="server"> <columns> <asp:boundfield datafield="au_id" headertext="Author ID" readonly="true"/> <asp:templatefield headertext="Last Name" itemstyle-verticalalign="Top"> <itemtemplate> <%#Eval("au_lname")%> </itemtemplate> <edititemtemplate> <asp:textbox id="LastNameTextBox" text='<%#Eval("au_lname")%>' width="90" runat="server"/> <br/> <asp:requiredfieldvalidator id="LastNameRequiredValidator" controltovalidate="LastNameTextBox" display="Dynamic" text="Please enter a last name." runat="server" /> </edititemtemplate> </asp:templatefield> <asp:templatefield headertext="First Name" itemstyle-verticalalign="Top"> <itemtemplate> <%#Eval("au_fname")%> </itemtemplate> <edititemtemplate> <asp:textbox id="FirstNameTextBox" text='<%#Eval("au_fname")%>' width="90" runat="server"/> <br/> <asp:requiredfieldvalidator id="FirstNameRequiredValidator" controltovalidate="FirstNameTextBox" display="Dynamic" text="Please enter a first name." runat="server" /> </edititemtemplate> </asp:templatefield> <asp:checkboxfield datafield="contract" headertext="Contract" readonly="true"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]" updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>


System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.TableRow
System.Web.UI.WebControls.GridViewRow


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


GridViewRow コンストラクタ
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ rowIndex As Integer, _ dataItemIndex As Integer, _ rowType As DataControlRowType, _ rowState As DataControlRowState _ )
Dim rowIndex As Integer Dim dataItemIndex As Integer Dim rowType As DataControlRowType Dim rowState As DataControlRowState Dim instance As New GridViewRow(rowIndex, dataItemIndex, rowType, rowState)
public GridViewRow ( int rowIndex, int dataItemIndex, DataControlRowType rowType, DataControlRowState rowState )
public: GridViewRow ( int rowIndex, int dataItemIndex, DataControlRowType rowType, DataControlRowState rowState )
public GridViewRow ( int rowIndex, int dataItemIndex, DataControlRowType rowType, DataControlRowState rowState )
public function GridViewRow ( rowIndex : int, dataItemIndex : int, rowType : DataControlRowType, rowState : DataControlRowState )


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


GridViewRow プロパティ



名前 | 説明 | |
---|---|---|
![]() | System.Web.UI.IDataItemContainer.DataItem | このメンバの説明については、DataItem のトピックを参照してください。 |
![]() | System.Web.UI.IDataItemContainer.DataItemIndex | このメンバの説明については、DataItemIndex のトピックを参照してください。 |
![]() | System.Web.UI.IDataItemContainer.DisplayIndex | このメンバの説明については、DisplayIndex のトピックを参照してください。 |

GridViewRow メソッド



GridViewRow メンバ
GridViewRow データ型で公開されるメンバを以下の表に示します。






名前 | 説明 | |
---|---|---|
![]() | DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。(Control から継承されます。) |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。(Control から継承されます。) |
![]() | Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。(Control から継承されます。) |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。(Control から継承されます。) |
![]() | PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。(Control から継承されます。) |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。(Control から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Web.UI.IDataItemContainer.DataItem | このメンバの説明については、DataItem のトピックを参照してください。 |
![]() | System.Web.UI.IDataItemContainer.DataItemIndex | このメンバの説明については、DataItemIndex のトピックを参照してください。 |
![]() | System.Web.UI.IDataItemContainer.DisplayIndex | このメンバの説明については、DisplayIndex のトピックを参照してください。 |

- GridViewRowのページへのリンク