ObjectDataSourceView.UpdateParameters Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la collection de paramètres contenant les paramètres qui sont utilisés par la méthode UpdateMethod.
public:
property System::Web::UI::WebControls::ParameterCollection ^ UpdateParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
public System.Web.UI.WebControls.ParameterCollection UpdateParameters { get; }
member this.UpdateParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property UpdateParameters As ParameterCollection
Valeur de propriété
ParameterCollection qui contient les paramètres utilisés par la propriété UpdateMethod.
Exemples
L’exemple de code suivant montre comment utiliser un DropDownList contrôle, TextBox des contrôles et plusieurs ObjectDataSource contrôles pour mettre à jour les données. Le DropDownList nom d’un NorthwindEmployee
, tandis que les TextBox contrôles sont utilisés pour entrer et mettre à jour les informations d’adresse. Étant donné que la UpdateParameters collection contient un ControlParameter objet lié à la valeur sélectionnée du DropDownList, le bouton qui déclenche l’opération Update n’est activé qu’une fois qu’un employé est sélectionné.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<%@ Import namespace="Samples.AspNet.CS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
// Add parameters and initialize the user interface
// only if an employee is selected.
private void Page_Load(object sender, EventArgs e)
{
// Be sure the text boxes are initialized with
// data from the currently selected employee.
NorthwindEmployee selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue);
if (selectedEmployee != null) {
AddressBox.Text = selectedEmployee.Address;
CityBox.Text = selectedEmployee.City;
PostalCodeBox.Text = selectedEmployee.PostalCode;
Button1.Enabled = true;
}
else {
Button1.Enabled = false;
}
}
// Press the button to update.
private void Btn_UpdateEmployee (object sender, CommandEventArgs e) {
ObjectDataSource2.Update();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ObjectDataSource - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<!-- The DropDownList is bound to the first ObjectDataSource. -->
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetAllEmployees"
typename="Samples.AspNet.CS.EmployeeLogic" />
<p><asp:dropdownlist
id="DropDownList1"
runat="server"
datasourceid="ObjectDataSource1"
datatextfield="FullName"
datavaluefield="EmpID"
autopostback="True" /></p>
<!-- The second ObjectDataSource performs the Update. This
preserves the state of the DropDownList, which otherwise
would rebind when the DataSourceChanged event is
raised as a result of an Update operation. -->
<!-- Security Note: The ObjectDataSource uses a FormParameter,
Security Note: which does not perform validation of input from the client.
Security Note: To validate the value of the FormParameter,
Security Note: handle the Updating event. -->
<asp:objectdatasource
id="ObjectDataSource2"
runat="server"
updatemethod="UpdateEmployeeWrapper"
typename="Samples.AspNet.CS.EmployeeLogic">
<updateparameters>
<asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
<asp:formparameter name="anAddress" formfield="AddressBox" />
<asp:formparameter name="aCity" formfield="CityBox" />
<asp:formparameter name="aPostalCode" formfield="PostalCodeBox" />
</updateparameters>
</asp:objectdatasource>
<p><asp:textbox
id="AddressBox"
runat="server" /></p>
<p><asp:textbox
id="CityBox"
runat="server" /></p>
<p><asp:textbox
id="PostalCodeBox"
runat="server" /></p>
<asp:button
id="Button1"
runat="server"
text="Update Employee"
oncommand="Btn_UpdateEmployee" />
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<%@ Import namespace="Samples.AspNet.VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' Add parameters and initialize the user interface
' only if an employee is selected.
Private Sub Page_Load(sender As Object, e As EventArgs)
' Be sure the text boxes are initialized with
' data from the currently selected employee.
Dim selectedEmployee As NorthwindEmployee
selectedEmployee = EmployeeLogic.GetEmployee(DropDownList1.SelectedValue)
If Not selectedEmployee Is Nothing Then
AddressBox.Text = selectedEmployee.Address
CityBox.Text = selectedEmployee.City
PostalCodeBox.Text = selectedEmployee.PostalCode
Button1.Enabled = True
Else
Button1.Enabled = False
End If
End Sub ' Page_Load
' Press the button to update.
Private Sub Btn_UpdateEmployee (sender As Object, e As CommandEventArgs )
ObjectDataSource2.Update()
End Sub ' Btn_UpdateEmployee
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ObjectDataSource - VB Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<!-- The DropDownList is bound to the first ObjectDataSource. -->
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetAllEmployees"
typename="Samples.AspNet.VB.EmployeeLogic" />
<p><asp:dropdownlist
id="DropDownList1"
runat="server"
datasourceid="ObjectDataSource1"
datatextfield="FullName"
datavaluefield="EmpID"
autopostback="True" /></p>
<!-- The second ObjectDataSource performs the Update. This
preserves the state of the DropDownList, which otherwise
would rebind when the DataSourceChanged event is
raised as a result of an Update operation. -->
<!-- Security Note: The ObjectDataSource uses a FormParameter,
Security Note: which does not perform validation of input from the client.
Security Note: To validate the value of the FormParameter,
Security Note: handle the Updating event. -->
<asp:objectdatasource
id="ObjectDataSource2"
runat="server"
updatemethod="UpdateEmployeeWrapper"
typename="Samples.AspNet.VB.EmployeeLogic">
<updateparameters>
<asp:controlparameter name="anID" controlid="DropDownList1" propertyname="SelectedValue" />
<asp:formparameter name="anAddress" formfield="AddressBox" />
<asp:formparameter name="aCity" formfield="CityBox" />
<asp:formparameter name="aPostalCode" formfield="PostalCodeBox" />
</updateparameters>
</asp:objectdatasource>
<p><asp:textbox
id="AddressBox"
runat="server" /></p>
<p><asp:textbox
id="CityBox"
runat="server" /></p>
<p><asp:textbox
id="PostalCodeBox"
runat="server" /></p>
<asp:button
id="Button1"
runat="server"
text="Update Employee"
oncommand="Btn_UpdateEmployee" />
</form>
</body>
</html>
Remarques
Les noms et les types des paramètres contenus dans la UpdateParameters collection doivent correspondre aux noms et types des paramètres qui se trouvent dans la méthode spécifiée par la UpdateMethod signature de propriété. Les noms de paramètres sont affectés par la propriété et respectent la OldValuesParameterFormatString casse. Lors de l’utilisation de contrôles liés aux données qui fournissent des paramètres, tels que GridView et DetailsView, le ObjectDataSource contrôle fusionne automatiquement tous les paramètres spécifiés explicitement dans la collection avec ces paramètres fournis par le contrôle lié aux données. Pour plus d'informations, consultez ObjectDataSource.UpdateMethod.