GridView.UpdateRow(Int32, Boolean) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
행의 필드 값을 사용하여 지정된 행 인덱스의 레코드를 업데이트합니다.
public:
virtual void UpdateRow(int rowIndex, bool causesValidation);
public virtual void UpdateRow(int rowIndex, bool causesValidation);
abstract member UpdateRow : int * bool -> unit
override this.UpdateRow : int * bool -> unit
Public Overridable Sub UpdateRow (rowIndex As Integer, causesValidation As Boolean)
매개 변수
- rowIndex
- Int32
업데이트할 행의 인덱스입니다.
- causesValidation
- Boolean
true이 메서드를 호출할 때 페이지 유효성 검사를 수행하려면 그렇지 않으면 . false
예외
컨트롤은 GridView 데이터 원본 컨트롤에 바인딩되지만 DataSourceView 데이터 원본과 연결된 컨트롤은 입니다 null.
예제
다음 예제에서는 프로그래밍 방식으로 컨트롤에서 UpdateRow 레코드를 업데이트 하는 메서드를 사용 하는 방법을 보여 줍니다 GridView .
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView UpdateRow Example</title>
</head>
<body>
<form id="form1" 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="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView UpdateRow Example</title>
</head>
<body>
<form id="form1" 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>
설명
메서드를 UpdateRow 사용하여 데이터 원본의 지정된 인덱스에서 레코드를 프로그래밍 방식으로 업데이트합니다. 이 메서드는 페이지의 다른 컨트롤과 같이 컨트롤 외부에서 레코드를 GridView 업데이트해야 하는 경우에 일반적으로 사용됩니다.
메모
이 메서드는 현재 편집 모드에 있는 행 또는 양방향 데이터 바인딩된 입력 컨트롤이 포함된 행에 대해서만 호출할 수 있습니다. 양방향 바인딩 식에 대한 자세한 내용은 데이터베이스에 바인딩을 참조하세요.
업데이트 작업 전에 페이지 유효성 검사를 수행할지 여부를 지정하려면 매개 변수를 causesValidation 사용합니다. 이 메서드를 호출하면 이벤트 및 RowUpdated 이벤트도 발생합니다RowUpdating.