GridView.EditIndex プロパティ
アセンブリ: System.Web (system.web.dll 内)

編集する行の 0 から始まるインデックス。既定値は -1 で、行が編集されないことを示します。


EditIndex プロパティを使用して、編集する GridView コントロールの行をプログラムによって指定または確認します。このプロパティがコントロールの行のインデックスに設定されている場合、その行が編集モードになります。編集モードでは、行の読み取り専用ではない各列フィールドに、そのフィールドのデータ型に適した入力コントロール (TextBox コントロールなど) が表示されます。これにより、ユーザーがフィールドの値を変更できます。編集モードを終了するには、このプロパティを -1 に設定します。
![]() |
---|
GridView コントロールには、このプロパティを自動設定する組み込みの編集機能があります。通常、このプロパティは、編集される行をプログラムによって確認する必要がある場合、または GridView コントロールに独自のカスタム編集機能を追加する場合のみ使用します。 |

EditIndex プロパティを使用して、GridView コントロールの編集中の行を確認する方法を次のコード例に示します。行が更新されると、正常に更新されたことを示すメッセージが表示されます。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' Clear the message label when the user enters edit mode. If e.CommandName = "Edit" Then Message.Text = "" End If End Sub Sub CustomersGridView_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) ' The update operation was successful. Retrieve the row being edited. Dim index As Integer = CustomersGridView.EditIndex Dim row As GridViewRow = CustomersGridView.Rows(index) ' Notify the user that the update was successful. Message.Text = "Updated record " & row.Cells(1).Text + "." End Sub Sub CustomersGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) ' The update operation was canceled. Display the appropriate message. Message.Text = "Update operation canceled." End Sub </script> <html> <body> <form runat="server"> <h3>GridView Rows Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- 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" onrowupdated="CustomersGridView_RowUpdated" onrowcancelingedit="CustomersGridView_RowCancelingEdit" 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)" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) { // Clear the message label when the user enters edit mode. if (e.CommandName == "Edit") { Message.Text = ""; } } void CustomersGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e) { // The update operation was successful. Retrieve the row being edited. int index = CustomersGridView.EditIndex; GridViewRow row = CustomersGridView.Rows[index]; // Notify the user that the update was successful. Message.Text = "Updated record " + row.Cells[1].Text + "."; } void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e) { // The update operation was canceled. Display the appropriate message. Message.Text = "Update operation canceled."; } </script> <html> <body> <form runat="server"> <h3>GridView Rows Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- 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" onrowupdated="CustomersGridView_RowUpdated" onrowcancelingedit="CustomersGridView_RowCancelingEdit" 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)" deletecommand="Delete from Customers 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.EditIndex プロパティを検索する場合は、下記のリンクをクリックしてください。

- GridView.EditIndex プロパティのページへのリンク