ControlParameter.PropertyName Propiedad

Definición

Obtiene o establece el nombre de propiedad del control identificado por la propiedad ControlID al que se enlaza el objeto ControlParameter.Gets or sets the property name of the control identified by the ControlID property that the ControlParameter object binds to.

public:
 property System::String ^ PropertyName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.ControlPropertyNameConverter))]
public string PropertyName { get; set; }
member this.PropertyName : string with get, set
Public Property PropertyName As String

Valor de propiedad

Una cadena string que representa el nombre de la propiedad de un control a la que se enlaza ControlParameter.A string that represents the name of a control's property that the ControlParameter binds to.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo ControlParameter usar un objeto para enlazar datos ListBox mostrados en un control al valor DropDownList seleccionado de un control en un escenario declarativo.The following code example demonstrates how to use a ControlParameter object to bind data displayed in a ListBox control to the selected value of a DropDownList control in a declarative scenario. El DropDownList control se deriva ListControl del control.The DropDownList control derives from the ListControl control. El ControlParameter objeto se agrega a la SelectParameters colección del SqlDataSource control en el formulario y se corresponde con el texto del@Titlemarcador de posición "" SelectCommand de la propiedad.The ControlParameter object is added to the SelectParameters collection of the SqlDataSource control on the form, and corresponds to the "@Title" placeholder text in the SelectCommand property.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

    </form>
  </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected="True">Sales Representative</asp:listitem>
          <asp:listitem>Sales Manager</asp:listitem>
          <asp:listitem>Vice President, Sales</asp:listitem>
      </asp:dropdownlist></p>

      <asp:sqldatasource
          id="SqlDataSource1"
          runat="server"
          connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
          selectcommand="SELECT LastName FROM Employees WHERE Title = @Title">
          <selectparameters>
              <asp:controlparameter name="Title" controlid="DropDownList1" propertyname="SelectedValue"/>
          </selectparameters>
      </asp:sqldatasource>

      <p><asp:listbox
          id="ListBox1"
          runat="server"
          datasourceid="SqlDataSource1"
          datatextfield="LastName">
      </asp:listbox></p>

    </form>
  </body>
</html>

En el ejemplo de código siguiente se muestra cómo ControlID establecer PropertyName las propiedades y para identificar el control ControlParameter al que está enlazado un objeto.The following code example demonstrates how to set the ControlID and PropertyName properties to identify the control that a ControlParameter object is bound to. En el ejemplo se rellena ListBox un control con valores.The example populates a ListBox control with values. La SelectedValue propiedad SqlDataSource del control se utiliza para filtrar los datos recuperados por un control y mostrados por un GridView control. ListBoxThe SelectedValue property of the ListBox control is used to filter data retrieved by a SqlDataSource control and displayed by a GridView control.

<%@ 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">
private void Page_Load(object sender, System.EventArgs e)
{
  if (IsPostBack) {
    GridView1.DataBind();
  }
  else {
    ListBox1.Items.Add(new ListItem("Nancy Davolio",   "1",true));
    ListBox1.Items.Add(new ListItem("Janet Leverling", "3",true));
    ListBox1.Items.Add(new ListItem("Margaret Peacock","4",true));
    ListBox1.Items.Add(new ListItem("Michael Suyama",  "6",true));
    ListBox1.Items.Add(new ListItem("Robert King",     "7",true));
    ListBox1.Items.Add(new ListItem("Anne Dodsworth",  "9",true));
  }
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show Orders For:</p>

      <p>
      <asp:ListBox
        id="ListBox1"
        runat="server"
        AutoPostBack="True">
      </asp:ListBox></p>

      <asp:SqlDataSource
        id="OdbcDataSource1"
        runat="server"
        ProviderName="System.Data.Odbc"
        DataSourceMode="DataSet"
        SelectCommand="SELECT OrderID, ShipName FROM Orders WHERE EmployeeID = ?;"
        ConnectionString="dsn=MyOdbcDSN;">
        <SELECTPARAMETERS>
          <asp:ControlParameter
            PropertyName="SelectedValue"
            ControlID="ListBox1"
            Name="empID">
          </asp:ControlParameter>
        </SELECTPARAMETERS>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
        id="GridView1"
        runat="server"
        DataSourceID="OdbcDataSource1">
      </asp:GridView></p>
    </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">
Private Sub Page_Load(sender As Object, e As EventArgs)

    If (IsPostBack) Then
        GridView1.DataBind()
    Else
      Dim li As ListItem

      li = New ListItem("Nancy Davolio",   "1",True)
      ListBox1.Items.Add(li)

      li = New ListItem("Janet Leverling", "3",True)
      ListBox1.Items.Add(li)

      li = New ListItem("Margaret Peacock","4",True)
      ListBox1.Items.Add(li)

      li = New ListItem("Michael Suyama",  "6",True)
      ListBox1.Items.Add(li)

      li = New ListItem("Robert King",     "7",True)
      ListBox1.Items.Add(li)

      li = New ListItem("Anne Dodsworth",  "9",True)
      ListBox1.Items.Add(li)
    End If
End Sub ' Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
      <p>Show Orders For:</p>

      <p>
      <asp:ListBox
        id="ListBox1"
        runat="server"
        AutoPostBack="True">
      </asp:ListBox></p>

      <asp:SqlDataSource
        id="OdbcDataSource1"
        runat="server"
        ProviderName="System.Data.Odbc"
        DataSourceMode="DataSet"
        SelectCommand="SELECT OrderID, ShipName FROM Orders WHERE EmployeeID = ?;"
        ConnectionString="dsn=MyOdbcDSN;">
        <SELECTPARAMETERS>
          <asp:ControlParameter
            PropertyName="SelectedValue"
            ControlID="ListBox1"
            Name="empID">
          </asp:ControlParameter>
        </SELECTPARAMETERS>
      </asp:SqlDataSource>

      <p>
      <asp:GridView
        id="GridView1"
        runat="server"
        DataSourceID="OdbcDataSource1">
      </asp:GridView></p>
    </form>
  </body>
</html>

Comentarios

La PropertyName propiedad identifica la propiedad pública Control del objeto identificado por la ControlID propiedad a la que ControlParameter se enlaza el objeto en tiempo de ejecución.The PropertyName property identifies the public property of the Control object identified by the ControlID property that the ControlParameter object binds to at run time. PropertyNamese puede establecer en una cadena simple, como "SelectedValue", o una expresión que use Eval la sintaxis para identificar propiedades de control complejas.PropertyName can be set to a simple string, such as "SelectedValue", or an expression using Eval syntax to identify complex control properties.

Aunque la PropertyName propiedad es opcional, ControlID normalmente se establecen PropertyName las propiedades y para que Evaluate el método se enlace correctamente a un control.While the PropertyName property is optional, typically both ControlID and PropertyName properties are set for the Evaluate method to correctly bind to a control. Si ControlID establece la propiedad pero no la Evaluate PropertyName propiedad, el método intenta usar el ControlValuePropertyAttribute atributo para identificar una propiedad predeterminada PropertyName .If you set the ControlID property but not the PropertyName property, the Evaluate method attempts to use the ControlValuePropertyAttribute attribute to identify a default PropertyName property. (Es responsabilidad de los autores de controles especificar este atributo). Si se produce un Evaluate error, se ArgumentException produce una excepción.(It is the responsibility of control authors to specify this attribute.) If this fails, Evaluate throws an ArgumentException exception.

En la tabla siguiente se identifican los controles ASP.net que ControlValuePropertyAttribute decoran las propiedades con el atributo.The following table identifies which ASP.NET controls decorate properties with the ControlValuePropertyAttribute attribute.

ControlControl Propiedad.Property
Calendar SelectedDate
CheckBox Checked
DataList SelectedValue
DetailsView SelectedValue
FormView SelectedValue
GridView SelectedValue
Label Text
ListControl SelectedValue
Menu SelectedValue
TextBox Text
TreeView SelectedValue

Se aplica a

Consulte también: