ListControl 构造函数 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ListControl 类的新实例。
public:
 ListControl();public ListControl ();Public Sub New ()示例
下面的代码示例演示如何以编程方式
创建 ListBox 控件。 该示例使用 控件 PlaceHolder 作为 的 ListBox容器。
<!-- 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" %>
<!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>ListBox Example</title>
<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>
   <br />
 
   <form id="form1" 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="VB" AutoEventWireup="True" %>
<!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>ListBox Example</title>
<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>
   <br />
 
   <form id="form1" 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>