ControlParameter.ControlID Eigenschaft
Definition
Gibt den Namen des Steuerelements an, an das das ControlParameter-Objekt gebunden wird.Specifies the name of the control that the ControlParameter object binds to.
public:
property System::String ^ ControlID { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.ControlIDConverter))]
public string ControlID { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.ControlIDConverter))>]
member this.ControlID : string with get, set
Public Property ControlID As String
Eigenschaftswert
Ein string
, der den Namen eines Webserver-Steuerelements darstellt.A string
that represents the name of a Web server control.
- Attribute
Beispiele
Im folgenden Codebeispiel wird veranschaulicht, wie ein- ControlParameter Objekt verwendet wird, um in einem-Steuerelement angezeigte Daten ListBox DropDownList in einem deklarativen Szenario an den ausgewählten Wert eines-Steuer Elements zu binden.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. Das ControlParameter -Objekt wird der SelectParameters -Auflistung des SqlDataSource -Steuer Elements auf dem Formular hinzugefügt und entspricht dem @Title Platzhalter Text in der- SelectCommand Eigenschaft.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>
Im folgenden Codebeispiel wird veranschaulicht, wie die ControlID Eigenschaften und festgelegt werden PropertyName , um das Steuerelement zu identifizieren, an das ein- ControlParameter Objekt gebunden ist.The following code example demonstrates how to set the ControlID and PropertyName properties to identify the control that a ControlParameter object is bound to. Im Beispiel wird ein- ListBox Steuerelement mit-Werten aufgefüllt.The example populates a ListBox control with values. Die SelectedValue -Eigenschaft des- ListBox Steuer Elements dient zum Filtern von Daten, die von einem SqlDataSource -Steuerelement abgerufen und von einem-Steuerelement angezeigt GridView werdenThe 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>
Hinweise
Die- ControlID Eigenschaft ist eine erforderliche Eigenschaft, die die Control Instanz identifiziert, an die das Objekt zur ControlParameter Laufzeit gebunden wird.The ControlID property is a required property that identifies the Control instance that the ControlParameter object binds to at run time.
In der Regel ControlID PropertyName werden die Eigenschaften und festgelegt, damit die Evaluate Methode ordnungsgemäß an ein Steuerelement gebunden wird.Typically, the ControlID and PropertyName properties are set for the Evaluate method to correctly bind to a control. Wenn Sie die-Eigenschaft nicht festlegen ControlID , löst die Evaluate Methode eine Ausnahme aus, ArgumentException Wenn aufgerufen wird.If you do not set the ControlID property, the Evaluate method throws an ArgumentException exception when called.