Export (0) Print
Expand All

ControlParameter.PropertyName Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the property name of the control identified by the ControlID property that the ControlParameter object binds to.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public string PropertyName { get; set; }
/** @property */
public String get_PropertyName ()

/** @property */
public void set_PropertyName (String value)

public function get PropertyName () : String

public function set PropertyName (value : String)

Property Value

A string that represents the name of a control's property that the ControlParameter binds to.

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. PropertyName can be set to a simple string, such as "SelectedValue", or an expression using Eval syntax to identify complex control properties.

While the PropertyName property is optional, typically both ControlID and PropertyName properties are set for the Evaluate method to correctly bind to a control. 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. (It is the responsibility of control authors to specify this attribute.) If this fails, Evaluate throws an ArgumentException exception.

The following table identifies which ASP.NET controls decorate properties with the ControlValuePropertyAttribute attribute.

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. 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>
  <body>
    <form runat="server">

      <p><asp:dropdownlist
          id="DropDownList1"
          runat="server"
          autopostback="True">
          <asp:listitem selected>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>
  <BODY>
    <FORM runat="server">

      <p><asp:DropDownList
          id="DropDownList1"
          runat="server"
          AutoPostBack="True">
          <asp:ListItem Selected>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="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
          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>

The following code example demonstrates how to set the ControlID and PropertyName properties to identify the control that a ControlParameter object is bound to. The example populates a ListBox control with values. The 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>
  <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="VJ#"%>
<!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 (get_IsPostBack()) {
            GridView1.DataBind();
        }
        else {
            ListBox1.get_Items().Add(new ListItem("Nancy Davolio", "1"));
            ListBox1.get_Items().Add(new ListItem("Janet Leverling", "3"));
            ListBox1.get_Items().Add(new ListItem("Margaret Peacock", "4"));
            ListBox1.get_Items().Add(new ListItem("Michael Suyama", "6"));
            ListBox1.get_Items().Add(new ListItem("Robert King", "7"));
            ListBox1.get_Items().Add(new ListItem("Anne Dodsworth", "9"));
        }
    }//Page_Load
</SCRIPT>

<HTML>
  <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>

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft