This documentation is archived and is not being maintained.

SelectionList.SelectedIndexChanged Event

Occurs whenever a user changes the selection of a SelectionList object.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

public event EventHandler SelectedIndexChanged
<asp:SelectionList OnSelectedIndexChanged="EventHandler" />

Changing the selection on the client does not generate a postback event. This event is called on the server if a postback event is generated by some other control and the selection has changed.

The following code example shows how to use the SelectedIndexChanged event. It also shows how to use the Rows property on postback to expand the list.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Syntax Overview.

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

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
        if (!IsPostBack)
            // Create data for the list
            ArrayList arr = new ArrayList();
            arr.Add (new 
                Task ("Verify transactions", "Done"));
            arr.Add (new 
                Task ("Check balance sheet", "Scheduled"));
            arr.Add (new 
                Task ("Call customer",       "Done"));
            arr.Add (new 
                Task ("Issue checks",          "Pending"));
            arr.Add (new 
                Task ("Send report",         "Pending"));
            arr.Add (new 
                Task ("Attend meeting",      "Scheduled"));

            // Set properties for the list
            SelList1.SelectType = 
            SelList1.Wrapping = Wrapping.NoWrap;
            SelList1.DataValueField = "Status";
            SelList1.DataTextField  = "TaskName";
            SelList1.Rows = 3;

            // Bind the list to the data
            SelList1.DataSource = arr;
            SelList1.DataBind ();

            Label1.Text = "Select an item and click the button.";
            Label2.Text = "Tasks are arranged by priority";

    void ShowStatus(Object sender, EventArgs e)
        string statusSpec = "Status: {0} is {1}";
        string prioSpec = "Priority: {0}";

        // Expand the list to show all items
        SelList1.Rows = SelList1.Items.Count;

        // Display the status
        Label1.Text = String.Format(statusSpec, 
        // Display the priority
        Label2.Text = String.Format(prioSpec, 
            (SelList1.SelectedIndex + 1));

    // Custom class for the task data 
    class Task
        private String _TaskName;
        private String _Status;

        public Task(String TaskName, String Status)
            _TaskName = TaskName;
            _Status = Status;
        public String TaskName { get { return _TaskName; } }
        public String Status { get { return _Status; } }

<html xmlns="" >
    <mobile:Form runat="server" id="Form1">
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />
        <mobile:SelectionList runat="server" id="SelList1" 
            OnSelectedIndexChanged="ShowStatus" />
        <mobile:Command ID="Command1" runat="server" 
            Text="Show Status" />

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1