ListControl-Konstruktor
Initialisiert eine neue Instanz der ListControl-Klasse.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Sub New
'Usage
Dim instance As New ListControl
public ListControl ()
public:
ListControl ()
public ListControl ()
public function ListControl ()
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie
ein ListBox-Steuerelement programmgesteuert erstellt wird. Im Beispiel wird ein PlaceHolder-Steuerelement als Container für die ListBox verwendet.
<!-- The following example demonstrates how to programmatically
create a ListBox. The example uses a PlaceHolder control as
a container for the ListBox. -->
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub SubmitBtn_Click(sender As Object, e As EventArgs)
' Create a new ListBox.
Dim listbox1 As New ListBox()
' Create ListItems to populate the ListBox.
Dim listItem1 As New ListItem("Item 1","Value 1")
Dim listItem2 As New ListItem("Item 2","Value 2")
' Add the ListItems to the ListBox.
listbox1.Items.Add(listItem1)
listbox1.Items.Add(listItem2)
' Add the ListBox to the Controls collection of the PlaceHolder control.
Place.Controls.Add(listbox1)
End Sub
</script>
</head>
<body>
<h3>ListBox Example</h3>
<p>
<form runat=server>
<asp:button id="Button1"
Text="Click to create a two-item ListBox"
OnClick="SubmitBtn_Click"
runat="server" />
<br><br>
<asp:PlaceHolder id="Place" runat="server"/>
</form>
</body>
</html>
<!-- The following example demonstrates how to programmatically
create a ListBox. The example uses a PlaceHolder control as
a container for the ListBox. -->
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void SubmitBtn_Click(Object sender, EventArgs e)
{
// Create a new ListBox.
ListBox listbox1 = new ListBox();
// Create ListItems to populate the ListBox.
ListItem listItem1 = new ListItem("Item 1","Value 1");
ListItem listItem2 = new ListItem("Item 2","Value 2");
// Add the ListItems to the ListBox.
listbox1.Items.Add(listItem1);
listbox1.Items.Add(listItem2);
// Add the ListBox to the Controls collection of the PlaceHolder control.
Place.Controls.Add(listbox1);
}
</script>
</head>
<body>
<h3>ListBox Example</h3>
<p>
<form runat=server>
<asp:button id="Button1"
Text="Click to create a two item ListBox"
OnClick="SubmitBtn_Click"
runat="server" />
<br><br>
<asp:PlaceHolder id="Place" runat="server"/>
</form>
</body>
</html>
Plattformen
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
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ListControl-Klasse
ListControl-Member
System.Web.UI.WebControls-Namespace