FormViewModeEventHandler 대리자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
ModeChanging 컨트롤의 FormView 이벤트를 처리하는 메서드를 나타냅니다.
public delegate void FormViewModeEventHandler(System::Object ^ sender, FormViewModeEventArgs ^ e);
public delegate void FormViewModeEventHandler(object sender, FormViewModeEventArgs e);
type FormViewModeEventHandler = delegate of obj * FormViewModeEventArgs -> unit
Public Delegate Sub FormViewModeEventHandler(sender As Object, e As FormViewModeEventArgs)
매개 변수
- sender
- Object
이벤트 소스입니다.
이벤트 데이터를 포함하는 FormViewModeEventArgs입니다.
예제
다음 예제에서는 프로그래밍 방식으로 추가 하는 방법에 설명를 FormViewModeEventHandler 위임할 합니다 ModeChanging 의 이벤트를 FormView 컨트롤.
중요
이 예제에서 컨트롤에 잠재적인 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.
<%@ Page language="C#" %>
<%@ import namespace="System.Data"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
// To dynamically create a template for a FormView control,
// you must create a custom template class to represent
// the template. This template class represents the item
// template for a FormView control.
private sealed class EmployeeItemTemplate : ITemplate
{
// When implementing the ITemplate interface, you must
// implement the InstantiateIn method. The FormView
// control calls this method to create the template's
// content.
void ITemplate.InstantiateIn(Control container)
{
// Create the child controls contained in the template.
// For this example, the item template displays the
// FirstName and LastName fields from the data source.
// To support data binding, create event handlers
// for the DataBinding event of each child control.
// The event handlers must bind the appropriate value
// to each control.
Label firstNameLabel = new Label();
firstNameLabel.ID = "FirstNameLabel";
firstNameLabel.DataBinding += new EventHandler(FirstNameLabel_DataBinding);
LiteralControl nameLineBreak = new LiteralControl("<br/>");
LiteralControl buttonLineBreak = new LiteralControl("<br/>");
Label lastNameLabel = new Label();
lastNameLabel.ID = "LastNameLabel";
lastNameLabel.DataBinding += new EventHandler(LastNameLabel_DataBinding);
Button editButton = new Button();
editButton.ID = "EditButton";
editButton.CommandName = "Edit";
editButton.Text = "Edit";
// Add the controls to the Controls collection of the
// container control.
container.Controls.Add(firstNameLabel);
container.Controls.Add(nameLineBreak);
container.Controls.Add(lastNameLabel);
container.Controls.Add(buttonLineBreak);
container.Controls.Add(editButton);
}
// This event handler binds the value of the FirstName field
// to the FirstNameLabel Label control displayed in the template.
private void FirstNameLabel_DataBinding(Object sender, EventArgs e)
{
// Use the sender parameter to retrieve the Label control
// being bound to data.
Label firstNameLabelControl = (Label)sender;
// Retrieve the value to bind to the Label control. First,
// use the NamingContainer property to retrieve the parent
// control of the Label control. In this example, the parent
// control is the FormView control.
FormView formViewContainer = (FormView)firstNameLabelControl.NamingContainer;
// Get the data item bound to the FormView control.
DataRowView rowView = (DataRowView)formViewContainer.DataItem;
// Use the data item to retrieve the value of the FirstName field.
// Set the Text property of the Label control to this value.
firstNameLabelControl.Text = rowView["FirstName"].ToString();
}
// This event handler binds the value of the LastName field
// to the LastNameLabel Label control displayed in the template.
private void LastNameLabel_DataBinding(Object sender, EventArgs e)
{
// Use the sender parameter to retrieve the Label control
// being bound to data.
Label lastNameLabelControl = (Label)sender;
// Retrieve the value to bind to the Label control. First,
// use the NamingContainer property to retrieve the parent
// control of the Label control. In this example, the parent
// control is the FormView control.
FormView formViewContainer = (FormView)lastNameLabelControl.NamingContainer;
// Get the data item bound to the FormView control.
DataRowView rowView = (DataRowView)formViewContainer.DataItem;
// Use the data item to retrieve the value of the LastName field.
// Set the Text property of the Label control to this value.
lastNameLabelControl.Text = rowView["LastName"].ToString();
}
}
// This template class represents the edit item
// template for a FormView control.
private sealed class EmployeeEditItemTemplate : ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
// Create the child controls contained in the template.
// The edit item template should contain the input
// controls for the user to edit a record.
TextBox firstNameTextBox = new TextBox();
firstNameTextBox.ID = "FirstNameTextBox";
LiteralControl nameLineBreak = new LiteralControl("<br/>");
LiteralControl buttonLineBreak = new LiteralControl("<br/>");
TextBox lastNameTextBox = new TextBox();
lastNameTextBox.ID = "LastNameTextBox";
Button updateButton = new Button();
updateButton.ID = "UpdateButton";
updateButton.CommandName = "Update";
updateButton.Text = "Update";
Button cancelButton = new Button();
cancelButton.ID = "CancelButton";
cancelButton.CommandName = "Cancel";
cancelButton.Text = "Cancel";
// Add the controls to the Controls collection of the
// container control.
container.Controls.Add(firstNameTextBox);
container.Controls.Add(nameLineBreak);
container.Controls.Add(lastNameTextBox);
container.Controls.Add(buttonLineBreak);
container.Controls.Add(updateButton);
container.Controls.Add(cancelButton);
}
}
void Page_Load(Object sender, EventArgs e)
{
// Create a new FormView object.
FormView employeesFormView = new FormView();
// Set the FormView object's properties.
employeesFormView.ID = "EmployeesFormView";
employeesFormView.DataSourceID = "EmployeeSource";
employeesFormView.AllowPaging = true;
employeesFormView.HeaderText = "Employee Name";
employeesFormView.DataKeyNames = new String[1] { "EmployeeID" };
// Programmatically register the event handlers for the
// the FormView control.
employeesFormView.ModeChanging += new FormViewModeEventHandler(EmployeeFormView_ModeChanging);
employeesFormView.ItemUpdating += new FormViewUpdateEventHandler(EmployeeFormView_ItemUpdating);
// Create the dynamic templates using the custom template classes.
employeesFormView.ItemTemplate = new EmployeeItemTemplate();
employeesFormView.EditItemTemplate = new EmployeeEditItemTemplate();
// Add the FormView object to the Controls collection
// of the PlaceHolder control.
FormViewPlaceHolder.Controls.Add(employeesFormView);
}
void EmployeeFormView_ItemUpdating(Object sender, FormViewUpdateEventArgs e)
{
// Because the FormView control is dynamically generated,
// the NewValues collection must be programmatically populated
// with the values for the record to update.
// Use the sender argument to retrieve the FormView
// control that raised the event.
FormView employeeFormView = (FormView)sender;
// Retrieve the data row from the FormView control.
FormViewRow row = employeeFormView.Row;
// Retrieve the TextBox controls that contain the updated values
// entered by the user.
TextBox firstNameTextBox = (TextBox)row.FindControl("FirstNameTextBox");
TextBox lastNameTextBox = (TextBox)row.FindControl("LastNameTextBox");
if (firstNameTextBox != null && lastNameTextBox != null)
{
// Add the new values to the NewValues collections.
e.NewValues.Add("FirstName", firstNameTextBox.Text);
e.NewValues.Add("LastName", lastNameTextBox.Text);
}
}
void EmployeeFormView_ModeChanging(Object sender, FormViewModeEventArgs e)
{
// Use the sender argument to retrieve the FormView
// control that raised the event.
FormView employeeFormView = (FormView)sender;
// Use the NewMode property to determine the mode to which the
// FormView control is transitioning.
switch (e.NewMode)
{
case FormViewMode.Edit:
// Hide the pager row and clear the Label control
// when transitioning to edit mode.
employeeFormView.AllowPaging = false;
MessageLabel.Text = "";
break;
case FormViewMode.ReadOnly:
// Display the pager row and confirmation message
// when transitioning to edit mode.
employeeFormView.AllowPaging = true;
if (e.CancelingEdit)
{
MessageLabel.Text = "Update canceled.";
}
else
{
MessageLabel.Text = "Update completed.";
}
break;
case FormViewMode.Insert:
// Cancel the mode change if the FormView
// control attempts to transition to insert
// mode.
e.Cancel = true;
break;
default:
MessageLabel.Text = "Unsupported mode.";
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView Example</h3>
<!-- Use a PlaceHolder control as the container for the -->
<!-- dynamically generated FormView control. -->
<asp:placeholder id="FormViewPlaceHolder"
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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName] From [Employees]"
updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName Where [EmployeeID]=@EmployeeID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
<%@ Page language="VB" %>
<%@ import namespace="System.Data"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' To dynamically create a template for a FormView control,
' you must create a custom template class to represent
' the template. This template class represents the item
' template for a FormView control.
Private NotInheritable Class EmployeeItemTemplate
Implements ITemplate
' When implementing the ITemplate interface, you must
' implement the InstantiateIn method. The FormView
' control calls this method to create the template's
' content.
Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
' Create the child controls contained in the template.
' For this example, the item template displays the
' FirstName and LastName fields from the data source.
' To support data binding, create event handlers
' for the DataBinding event of each child control.
' The event handlers must bind the appropriate value
' to each control.
Dim firstNameLabel As New Label()
firstNameLabel.ID = "FirstNameLabel"
AddHandler firstNameLabel.DataBinding, AddressOf FirstNameLabel_DataBinding
Dim nameLineBreak As New LiteralControl("<br/>")
Dim buttonLineBreak As New LiteralControl("<br/>")
Dim lastNameLabel As New Label()
lastNameLabel.ID = "LastNameLabel"
AddHandler lastNameLabel.DataBinding, AddressOf LastNameLabel_DataBinding
Dim editButton As New Button()
editButton.ID = "EditButton"
editButton.CommandName = "Edit"
editButton.Text = "Edit"
' Add the controls to the Controls collection of the
' container control.
container.Controls.Add(firstNameLabel)
container.Controls.Add(nameLineBreak)
container.Controls.Add(lastNameLabel)
container.Controls.Add(buttonLineBreak)
container.Controls.Add(editButton)
End Sub
' This event handler binds the value of the FirstName field
' to the FirstNameLabel Label control displayed in the template.
Private Sub FirstNameLabel_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
' Use the sender parameter to retrieve the Label control
' being bound to data.
Dim firstNameLabelControl As Label = CType(sender, Label)
' Retrieve the value to bind to the Label control. First,
' use the NamingContainer property to retrieve the parent
' control of the Label control. In this example, the parent
' control is the FormView control.
Dim formViewContainer As FormView = CType(firstNameLabelControl.NamingContainer, FormView)
' Get the data item bound to the FormView control.
Dim rowView As DataRowView = CType(formViewContainer.DataItem, DataRowView)
' Use the data item to retrieve the value of the FirstName field.
' Set the Text property of the Label control to this value.
firstNameLabelControl.Text = rowView("FirstName").ToString()
End Sub
' This event handler binds the value of the LastName field
' to the LastNameLabel Label control displayed in the template.
Private Sub LastNameLabel_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
' Use the sender parameter to retrieve the Label control
' being bound to data.
Dim lastNameLabelControl As Label = CType(sender, Label)
' Retrieve the value to bind to the Label control. First,
' use the NamingContainer property to retrieve the parent
' control of the Label control. In this example, the parent
' control is the FormView control.
Dim formViewContainer As FormView = CType(lastNameLabelControl.NamingContainer, FormView)
' Get the data item bound to the FormView control.
Dim rowView As DataRowView = CType(formViewContainer.DataItem, DataRowView)
' Use the data item to retrieve the value of the LastName field.
' Set the Text property of the Label control to this value.
lastNameLabelControl.Text = rowView("LastName").ToString()
End Sub
End Class
' This template class represents the edit item
' template for a FormView control.
Private NotInheritable Class EmployeeEditItemTemplate
Implements ITemplate
Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
' Create the child controls contained in the template.
' The edit item template should contain the input
' controls for the user to edit a record.
Dim firstNameTextBox As New TextBox()
firstNameTextBox.ID = "FirstNameTextBox"
Dim nameLineBreak As New LiteralControl("<br/>")
Dim buttonLineBreak As New LiteralControl("<br/>")
Dim lastNameTextBox As New TextBox()
lastNameTextBox.ID = "LastNameTextBox"
Dim updateButton As New Button()
updateButton.ID = "UpdateButton"
updateButton.CommandName = "Update"
updateButton.Text = "Update"
Dim cancelButton As New Button()
cancelButton.ID = "CancelButton"
cancelButton.CommandName = "Cancel"
cancelButton.Text = "Cancel"
' Add the controls to the Controls collection of the
' container control.
container.Controls.Add(firstNameTextBox)
container.Controls.Add(nameLineBreak)
container.Controls.Add(lastNameTextBox)
container.Controls.Add(buttonLineBreak)
container.Controls.Add(updateButton)
container.Controls.Add(cancelButton)
End Sub
End Class
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new FormView object.
Dim employeesFormView As New FormView()
' Set the FormView object's properties.
employeesFormView.ID = "EmployeesFormView"
employeesFormView.DataSourceID = "EmployeeSource"
employeesFormView.AllowPaging = True
employeesFormView.HeaderText = "Employee Name"
Dim keyArray() As String = {"EmployeeID"}
employeesFormView.DataKeyNames = keyArray
' Programmatically register the event handlers for the
' the FormView control.
AddHandler employeesFormView.ModeChanging, AddressOf EmployeeFormView_ModeChanging
AddHandler employeesFormView.ItemUpdating, AddressOf EmployeeFormView_ItemUpdating
' Create the dynamic templates using the custom template classes.
employeesFormView.ItemTemplate = New EmployeeItemTemplate()
employeesFormView.EditItemTemplate = New EmployeeEditItemTemplate()
' Add the FormView object to the Controls collection
' of the PlaceHolder control.
FormViewPlaceHolder.Controls.Add(employeesFormView)
End Sub
Sub EmployeeFormView_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs)
' Because the FormView control is dynamically generated,
' the NewValues collection must be programmatically populated
' with the values for the record to update.
' Use the sender argument to retrieve the FormView
' control that raised the event.
Dim employeeFormView As FormView = CType(sender, FormView)
' Retrieve the data row from the FormView control.
Dim row As FormViewRow = employeeFormView.Row
' Retrieve the TextBox controls that contain the updated values
' entered by the user.
Dim firstNameTextBox As TextBox = CType(row.FindControl("FirstNameTextBox"), TextBox)
Dim lastNameTextBox As TextBox = CType(row.FindControl("LastNameTextBox"), TextBox)
If firstNameTextBox IsNot Nothing And lastNameTextBox IsNot Nothing Then
' Add the new values to the NewValues collections.
e.NewValues.Add("FirstName", firstNameTextBox.Text)
e.NewValues.Add("LastName", lastNameTextBox.Text)
End If
End Sub
Sub EmployeeFormView_ModeChanging(ByVal sender As Object, ByVal e As FormViewModeEventArgs)
' Use the sender argument to retrieve the FormView
' control that raised the event.
Dim employeeFormView As FormView = CType(sender, FormView)
' Use the NewMode property to determine the mode to which the
' FormView control is transitioning.
Select Case e.NewMode
Case FormViewMode.Edit
' Hide the pager row and clear the Label control
' when transitioning to edit mode.
employeeFormView.AllowPaging = False
MessageLabel.Text = ""
Case FormViewMode.ReadOnly
' Display the pager row and confirmation message
' when transitioning to edit mode.
employeeFormView.AllowPaging = True
If e.CancelingEdit Then
MessageLabel.Text = "Update canceled."
Else
MessageLabel.Text = "Update completed."
End If
Case FormViewMode.Insert
' Cancel the mode change if the FormView
' control attempts to transition to insert
' mode.
e.Cancel = True
Case Else
MessageLabel.Text = "Unsupported mode."
End Select
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView Example</h3>
<!-- Use a PlaceHolder control as the container for the -->
<!-- dynamically generated FormView control. -->
<asp:placeholder id="FormViewPlaceHolder"
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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName] From [Employees]"
updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName Where [EmployeeID]=@EmployeeID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
다음 예제에서는 선언적으로 추가 하는 방법에 설명를 FormViewModeEventHandler 위임할 합니다 ModeChanging 의 이벤트를 FormView 컨트롤.
중요
이 예제에서 컨트롤에 잠재적인 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.
<%@ 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 EmployeeFormView_ModeChanging(Object sender, FormViewModeEventArgs e)
{
// Use the NewMode property to determine the mode to which the
// FormView control is transitioning.
switch (e.NewMode)
{
case FormViewMode.Edit:
// Hide the pager row and clear the Label control
// when transitioning to edit mode.
EmployeeFormView.AllowPaging = false;
MessageLabel.Text = "";
break;
case FormViewMode.ReadOnly:
// Display the pager row and confirmation message
// when transitioning to edit mode.
EmployeeFormView.AllowPaging = true;
if (e.CancelingEdit)
{
MessageLabel.Text = "Update canceled.";
}
else
{
MessageLabel.Text = "Update completed.";
}
break;
case FormViewMode.Insert:
// Cancel the mode change if the FormView
// control attempts to transition to insert
// mode.
e.Cancel = true;
break;
default:
MessageLabel.Text = "Unsupported mode.";
break;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewModeEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewModeEventArgs Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
onmodechanging="EmployeeFormView_ModeChanging"
runat="server">
<itemtemplate>
<table>
<tr>
<td rowspan="6">
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
<b>Title:</b>
</td>
<td>
<%# Eval("Title") %>
</td>
</tr>
<tr>
<td>
<b>Hire Date:</b>
</td>
<td>
<%# Eval("HireDate","{0:d}") %>
</td>
</tr>
<tr style="height:150" valign="top">
<td>
<b>Address:</b>
</td>
<td>
<%# Eval("Address") %><br/>
<%# Eval("City") %> <%# Eval("Region") %>
<%# Eval("PostalCode") %><br/>
<%# Eval("Country") %>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="Edit"
text="Edit"
commandname="Edit"
runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<edititemtemplate>
<table>
<tr>
<td rowspan="6">
<asp:image id="EmployeeEditImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="FirstNameUpdateTextBox"
Text="Name" />:</b>
</td>
<td>
<asp:textbox id="FirstNameUpdateTextBox"
text='<%# Bind("FirstName") %>'
accesskey="n" tabindex="1" runat="server"/>
<asp:textbox id="LastNameUpdateTextBox"
text='<%# Bind("LastName") %>'
accesskey="l" tabindex="2" runat="server"/>
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="TitleUpdateTextBox"
Text="Title" />:</b>
</td>
<td>
<asp:textbox id="TitleUpdateTextBox"
text='<%# Bind("Title") %>'
accesskey="t" tabindex="3" runat="server"/>
</td>
</tr>
<tr>
<b><asp:Label runat="server"
AssociatedControlID="HireDateUpdateTextBox"
Text="Hire Date" />:</b>
<td>
<asp:textbox id="HireDateUpdateTextBox"
text='<%# Bind("HireDate", "{0:d}") %>'
accesskey="h" tabindex="4" runat="server" />
</td>
</tr>
<tr style="height:150" valign="top">
<td>
<b><asp:Label runat="server"
AssociatedControlID="AddressUpdateTextBox"
Text="Address" />:</b>
</td>
<td>
<asp:textbox id="AddressUpdateTextBox"
text='<%# Bind("Address") %>'
accesskey="a" tabindex="5" runat="server"/>
<br/>
<asp:textbox id="CityUpdateTextBox"
text='<%# Bind("City") %>'
accesskey="c" tabindex="6" runat="server"/>
<asp:textbox id="RegionUpdateTextBox"
text='<%# Bind("Region") %>'
width="40"
accesskey="r" tabindex="7" runat="server"/>
<asp:textbox id="PostalCodeUpdateTextBox"
text='<%# Bind("PostalCode") %>'
width="60"
accesskey="p" tabindex="8" runat="server"/>
<br/>
<asp:textbox id="CountryUpdateTextBox"
text='<%# Bind("Country") %>'
accesskey="u" tabindex="9" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="UpdateButton"
text="Update" tabindex="10"
commandname="Update"
runat="server"/>
<asp:linkbutton id="CancelButton"
text="Cancel" tabindex="11"
commandname="Cancel"
runat="server"/>
</td>
</tr>
</table>
</edititemtemplate>
</asp:formview>
<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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country], [HireDate], [PhotoPath] From [Employees]"
updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title, [Address]=@Address, [City]=@City, [Region]=@Region, [PostalCode]=@PostalCode, [Country]=@Country Where [EmployeeID]=@EmployeeID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</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 EmployeeFormView_ModeChanging(ByVal sender As Object, ByVal e As FormViewModeEventArgs)
' Use the NewMode property to determine the mode to which the
' FormView control is transitioning.
Select Case e.NewMode
Case FormViewMode.Edit
' Hide the pager row and clear the Label control
' when transitioning to edit mode.
EmployeeFormView.AllowPaging = False
MessageLabel.Text = ""
Case FormViewMode.ReadOnly
' Display the pager row and confirmation message
' when transitioning to edit mode.
EmployeeFormView.AllowPaging = True
If e.CancelingEdit Then
MessageLabel.Text = "Update canceled."
Else
MessageLabel.Text = "Update completed."
End If
Case FormViewMode.Insert
' Cancel the mode change if the FormView
' control attempts to transition to insert
' mode.
e.Cancel = True
Case Else
MessageLabel.Text = "Unsupported mode."
End Select
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewModeEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewModeEventArgs Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
onmodechanging="EmployeeFormView_ModeChanging"
runat="server">
<itemtemplate>
<table>
<tr>
<td rowspan="6">
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
<b>Title:</b>
</td>
<td>
<%# Eval("Title") %>
</td>
</tr>
<tr>
<td>
<b>Hire Date:</b>
</td>
<td>
<%# Eval("HireDate","{0:d}") %>
</td>
</tr>
<tr style="height:150" valign="top">
<td>
<b>Address:</b>
</td>
<td>
<%# Eval("Address") %><br/>
<%# Eval("City") %> <%# Eval("Region") %>
<%# Eval("PostalCode") %><br/>
<%# Eval("Country") %>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="Edit"
text="Edit"
commandname="Edit"
runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<edititemtemplate>
<table>
<tr>
<td rowspan="6">
<asp:image id="EmployeeEditImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="FirstNameUpdateTextBox"
Text="Name" />:</b>
</td>
<td>
<asp:textbox id="FirstNameUpdateTextBox"
text='<%# Bind("FirstName") %>'
accesskey="n" tabindex="1" runat="server"/>
<asp:textbox id="LastNameUpdateTextBox"
text='<%# Bind("LastName") %>'
accesskey="l" tabindex="2" runat="server"/>
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="TitleUpdateTextBox"
Text="Title" />:</b>
</td>
<td>
<asp:textbox id="TitleUpdateTextBox"
text='<%# Bind("Title") %>'
accesskey="t" tabindex="3" runat="server"/>
</td>
</tr>
<tr>
<b><asp:Label runat="server"
AssociatedControlID="HireDateUpdateTextBox"
Text="Hire Date" />:</b>
<td>
<asp:textbox id="HireDateUpdateTextBox"
text='<%# Bind("HireDate", "{0:d}") %>'
accesskey="h" tabindex="4" runat="server" />
</td>
</tr>
<tr style="height:150" valign="top">
<td>
<b><asp:Label runat="server"
AssociatedControlID="AddressUpdateTextBox"
Text="Address" />:</b>
</td>
<td>
<asp:textbox id="AddressUpdateTextBox"
text='<%# Bind("Address") %>'
accesskey="a" tabindex="5" runat="server"/>
<br/>
<asp:textbox id="CityUpdateTextBox"
text='<%# Bind("City") %>'
accesskey="c" tabindex="6" runat="server"/>
<asp:textbox id="RegionUpdateTextBox"
text='<%# Bind("Region") %>'
width="40"
accesskey="r" tabindex="7" runat="server"/>
<asp:textbox id="PostalCodeUpdateTextBox"
text='<%# Bind("PostalCode") %>'
width="60"
accesskey="p" tabindex="8" runat="server"/>
<br/>
<asp:textbox id="CountryUpdateTextBox"
text='<%# Bind("Country") %>'
accesskey="u" tabindex="9" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="UpdateButton"
text="Update" tabindex="10"
commandname="Update"
runat="server"/>
<asp:linkbutton id="CancelButton"
text="Cancel" tabindex="11"
commandname="Cancel"
runat="server"/>
</td>
</tr>
</table>
</edititemtemplate>
</asp:formview>
<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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country], [HireDate], [PhotoPath] From [Employees]"
updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title, [Address]=@Address, [City]=@City, [Region]=@Region, [PostalCode]=@PostalCode, [Country]=@Country Where [EmployeeID]=@EmployeeID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
합니다 ModeChanging 이벤트는 때를 FormView 컨트롤 모드를 실제로 변경 되기 전에 하지만 편집, 삽입 및 읽기 전용 모드 사이 전환 하 려 합니다. 구성 하는 등 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다는 FormView 특정 모드에 대 한 제어 하거나이 이벤트가 발생할 때마다 모드 변경 내용을 취소 합니다.
FormViewModeEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.
확장 메서드
GetMethodInfo(Delegate) |
지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다. |
적용 대상
추가 정보
.NET