Classe SelectionList
Rende disponibile per un'interfaccia utente la funzionalità di selezione per un elenco.
public class System.Web.UI.MobileControls.SelectionList:
System.Web.UI.MobileControls.MobileControl,
System.Web.UI.MobileControls.IListControl,
System.Web.UI.IPostBackDataHandler
Osservazioni
La classe SelectionList gestisce la selezione di uno o più elementi selezionati. Il controllo SelectionList deriva direttamente dalla classe MobileControl e non dispone di proprietà di gestione dell'impaginazione, come la proprietà ItemWeight.
Esempio
In questo esempio la proprietà DataSource della classe SelectionList è una matrice denominata values
creata e compilata durante il caricamento della pagina iniziale. È possibile impostare la proprietà SelectType nel codice e visualizzare la selezione utilizzando due metodi alternativi durante i postback.
<%@ 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>
Requisiti
Spazio dei nomi: System.Web.UI.MobileControls
Assembly: System.Web.Mobile
Vedere anche
Controllo SelectionList | Accesso ai dati mediante i controlli elenco