SelectionList Class

Provides user interface (UI) selection capability for a list.

public class System.Web.UI.MobileControls.SelectionList: 
   System.Web.UI.MobileControls.MobileControl, 
   System.Web.UI.MobileControls.IListControl, 
   System.Web.UI.IPostBackDataHandler

Remarks

The SelectionList class maintains the selection of single or multiple selected items. The SelectionList control is derived directly from the MobileControl class and does not have any of the pagination handling properties, such as the ItemWeight property.

Example

In this example, the DataSource property of the SelectionList class is an array called values that is created and filled during the initial page load. You can set the SelectType property in the code and display the selection through two alternate means during postbacks.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="vb" runat="server">

Public Sub Page_Load(sender As Object, e As EventArgs)
   If Not IsPostBack Then
      Label1.Text = "Pick an item"

      ' Create and fill an array list.
      Dim values As New ArrayList
      values.Add("one")
      values.Add("two")
      values.Add("three")

      ' Bind the array to the list.
      SelectionList1.DataSource = values
      SelectionList1.DataBind

      ' Set the SelectType property.
      SelectionList1.SelectType = _
         System.Web.UI.MobileControls.ListSelectType.Radio
   End If
End Sub

Public Sub Button_Click(sender As Object, e As EventArgs)
   If SelectionList1.SelectedIndex > -1 Then
      ' To show the selection, get the Selection property.
      Label1.Text = "You have selected " + _
         SelectionList1.Selection.Text

      ' This is an alternate means of showing the selection
      ' using the MobileListItemCollection object.
      Label2.Text = "You have selected " + _
         SelectionList1.Items(SelectionList1.SelectedIndex).Text
   Else
      Label1.Text = "No items selected"
   End If
End Sub

</script>

<mobile:Form id="Form1" runat="server">
   <mobile:Label id="Label1" runat="server" Text="Show a list." />
   <mobile:Label runat="server" id="Label2" />
   <mobile:SelectionList runat="server" id="SelectionList1" />
   <mobile:Command OnClick="Button_Click" Text="Ok" runat="server"/>
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="c#" runat="server">

public void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      Label1.Text = "Pick an item";

      // Create and fill an array list.
      ArrayList values = new ArrayList();
      values.Add("one");
      values.Add("two");
      values.Add("three");

      // Bind the array to the list.
      SelectionList1.DataSource = values;
      SelectionList1.DataBind();

      // Set the SelectType property.
      SelectionList1.SelectType = 
         System.Web.UI.MobileControls.ListSelectType.Radio;
   }
}

public void Button_Click(Object sender, EventArgs e)
{
   if (SelectionList1.SelectedIndex > -1)
   {
      // To show the selection, get the Selection property.
      Label1.Text = "You have selected " +
         SelectionList1.Selection.Text;

      // This is an alternate means of showing the selection
      // using the MobileListItemCollection object.
      Label2.Text = "You have selected " +
      SelectionList1.Items[SelectionList1.SelectedIndex].Text;
   }
   else
   {
      Label1.Text = "No items selected";
   }
}

</script>

<mobile:Form id="Form1" runat="server">
   <mobile:Label id="Label1" runat="server" Text="Show a list." />
   <mobile:Label runat="server" id="Label2" />
   <mobile:SelectionList runat="server" id="SelectionList1" />
   <mobile:Command OnClick="Button_Click" Text="Ok" runat="server"/>
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

SelectionList Control | Accessing Data Using Listing Controls