MobileListItemCollection.Add 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将项添加到集合末尾。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站。
重载
| Add(String) | 将项添加到集合的末尾,用提供的字符串作为 Text 属性。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站。 | 
| Add(MobileListItem) | 将项添加到集合末尾。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站。 | 
Add(String)
将项添加到集合的末尾,用提供的字符串作为 Text 属性。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站。
public:
 virtual void Add(System::String ^ item);public virtual void Add(string item);abstract member Add : string -> unit
override this.Add : string -> unitPublic Overridable Sub Add (item As String)参数
- item
- String
要添加到集合末尾的项。
注解
创建具有指定文本的新列表项,然后将其添加到集合的末尾。
另请参阅
适用于
Add(MobileListItem)
将项添加到集合末尾。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站。
public:
 void Add(System::Web::UI::MobileControls::MobileListItem ^ item);public void Add(System.Web.UI.MobileControls.MobileListItem item);member this.Add : System.Web.UI.MobileControls.MobileListItem -> unitPublic Sub Add (item As MobileListItem)参数
- item
- MobileListItem
要添加到集合末尾的项。
示例
下面的代码示例演示如何使用 Add 方法将名为 的 _ml 项添加到 的 MobileListItemCollection末尾。
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label1.Text = "Select an item";
            // Create and fill an array list.
            ArrayList listValues = new ArrayList();
            listValues.Add("One");
            listValues.Add("Two");
            listValues.Add("Three");
            // Bind the array to the list.
            SelList1.DataSource = listValues;
            SelList1.DataBind();
            // Set the SelectType.
            SelList1.SelectType =
                System.Web.UI.MobileControls.ListSelectType.Radio;
        }
        else
        {
            if (SelList1.SelectedIndex > -1)
            {
                // To show the selection, use the Selection property.
                Label1.Text = "Your selection is " +
                    SelList1.Selection;
                // Or, show the selection by using 
                // the MobileListItemCollection class.
                // Get the index of the selected item
                int idx = SelList1.SelectedIndex;
                Label2.Text = "You have selected " +
                    SelList1.Items[idx].Text;
                // Insert a copy of the selected item
                MobileListItem mi = SelList1.Selection;
                Label3.Text = "The index of your selection is " + 
                    mi.Index.ToString();
                SelList1.Items.Insert(idx, 
                    new MobileListItem(mi.Text + " Copy"));
            }
            else
            {
                Label1.Text = "No items selected";
            }
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Show a list" />
        <mobile:Label id="Label2" runat="server" />
        <mobile:Label id="Label3" runat="server" />
        <mobile:SelectionList runat="server" 
            id="SelList1" />
        <mobile:Command id="Command1" runat="server" 
            Text=" OK " />
    </mobile:form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            Label1.Text = "Select an item"
            ' Create and fill an array list.
            Dim listValues As New ArrayList()
            listValues.Add("One")
            listValues.Add("Two")
            listValues.Add("Three")
            ' Bind the array to the list.
            SelList1.DataSource = listValues
            SelList1.DataBind()
            ' Set the SelectType.
            SelList1.SelectType = ListSelectType.Radio
        Else
            If (SelList1.SelectedIndex > -1) Then
                ' To show the selection, use the Selection property.
                Label1.Text = "Your selection is " & _
                    SelList1.Selection.Text
                ' Or, show the selection by using 
                ' the MobileListItemCollection class.
                ' Get the index of the selected item
                Dim idx As Integer = SelList1.SelectedIndex
                Label2.Text = "You have selected " & _
                    SelList1.Items(idx).Text
                ' Insert a copy of the selected item
                Dim mi As MobileListItem = SelList1.Selection
                Label3.Text = "The index of your selection is " & _
                    mi.Index.ToString()
                SelList1.Items.Insert(idx, _
                    New MobileListItem(mi.Text + " Copy"))
            Else
                Label1.Text = "No items selected"
            End If
        End If
    End Sub
</script>
<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Show a list" />
        <mobile:Label id="Label2" runat="server" />
        <mobile:Label id="Label3" runat="server" />
        <mobile:SelectionList runat="server" 
            id="SelList1" />
        <mobile:Command id="Command1" runat="server" 
            Text=" OK " />
    </mobile:form>
</body>
</html>
注解
根据所使用的语法, Add 方法将指定的项添加到集合的末尾,或者使用指定文本构造新的列表项,然后将其添加到集合的末尾。