GridView.UpdateRow メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As GridView Dim rowIndex As Integer Dim causesValidation As Boolean instance.UpdateRow(rowIndex, causesValidation)


UpdateRow メソッドを使用して、データ ソース内の指定したインデックス位置にあるレコードをプログラムによって更新します。通常、このメソッドは、GridView コントロール以外から (ページ上の別のコントロールなどから) レコードを更新する必要がある場合に使用されます。
![]() |
---|
このメソッドは、現在編集モードになっている行、または双方向のデータ バインド入力コントロールを含んだ行に対してのみ呼び出すことができます。双方向のバインド式の詳細については、「データベースへのバインド」を参照してください。 |
更新操作の前にページの検証を実行するかどうかを指定するには、causesValidation パラメータを使用します。また、このメソッドを呼び出すと、RowUpdated イベントと RowUpdating イベントも発生します。

UpdateRow メソッドを使用して、プログラムによって GridView コントロールのレコードを更新する方法を次のコード例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub UpdateRowButton_Click(ByVal sender As Object, ByVal e As EventArgs) ' Programmatically update the current record in edit mode. CustomersGridView.UpdateRow(CustomersGridView.EditIndex, True) End Sub Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' Enable the UpdateRowButton button only when the GridView control ' is in edit mode. Select Case e.CommandName Case "Edit" UpdateRowButton.Enabled = True Case "Cancel" UpdateRowButton.Enabled = False Case "Update" UpdateRowButton.Enabled = False Case Else UpdateRowButton.Enabled = False End Select End Sub </script> <html> <body> <form runat="server"> <h3>GridView UpdateRow Example</h3> <asp:button id="UpdateRowButton" text="Update Record" enabled="false" onclick="UpdateRowButton_Click" runat="server"/> <hr/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" allowpaging="true" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogenerateeditbutton="true" datakeynames="CustomerID" onrowcommand="CustomersGridView_RowCommand" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" 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"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void UpdateRowButton_Click(Object sender, EventArgs e) { // Programmatically update the current record in edit mode. CustomersGridView.UpdateRow(CustomersGridView.EditIndex, true); } void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) { // Enable the UpdateRowButton button only when the GridView control // is in edit mode. switch (e.CommandName) { case "Edit": UpdateRowButton.Enabled = true; break; case "Cancel": UpdateRowButton.Enabled = false; break; case "Update": UpdateRowButton.Enabled = false; break; default: UpdateRowButton.Enabled = false; break; } } </script> <html> <body> <form runat="server"> <h3>GridView UpdateRow Example</h3> <asp:button id="UpdateRowButton" text="Update Record" enabled="false" onclick="UpdateRowButton_Click" runat="server"/> <hr/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" allowpaging="true" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogenerateeditbutton="true" datakeynames="CustomerID" onrowcommand="CustomersGridView_RowCommand" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" 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"> </asp:sqldatasource> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGridView.UpdateRow メソッドを検索する場合は、下記のリンクをクリックしてください。

- GridView.UpdateRow メソッドのページへのリンク