SelectionList 类 移动

SelectionList 类维护选择的单个或多个选择项。SelectionList 直接从 MobileControl 类派生而且不具有任何分页处理属性,如 ItemWeight 属性。

在下面的代码示例中,SelectionList 类的 DataSource 属性是在初始页加载过程中创建的值的数组。可以更改 SelectType 属性的设置以查看不同版本的 SelectionList

 

 

<%@ 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  >
<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>

posted @ 2009-04-29 10:22  minmin8110  阅读(158)  评论(0)    收藏  举报