ASP.NET Tutorial/Mobile/SelectionList

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Selection List

   <source lang="csharp">

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Select" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <html xmlns="http://www.w3.org/1999/xhtml" > <body>

   <mobile:Form id="Form1" runat="server">
       Your skills?
<mobile:SelectionList runat="server" id="list" SelectType="checkbox" /> <mobile:Command ID="Command1" runat="server" OnClick="Button_Click" Text="Submit" /> </mobile:Form> <mobile:Form runat="server" id="ResultsForm"> <mobile:Label runat="server" id="Results" /> </mobile:Form>

</body> </html> File: Default.aspx.cs using System; using System.Collections; using System.ruponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Mobile; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.MobileControls; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; public partial class Select : System.Web.UI.MobileControls.MobilePage {

   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           ArrayList values = new ArrayList();
           values.Add("ASP.NET");
           values.Add("ADO.NET");
           values.Add("SQL Server");
           values.Add("XML");
           list.DataSource = values;
           list.DataBind();
       }
   }
   protected void Button_Click(object sender, EventArgs e)
   {
       string buf = "";
       foreach (MobileListItem item in list.Items)
           buf += (item.Selected ? item.Text + ", " : "");
       buf = buf.TrimEnd();
       if (buf.EndsWith(","))
           buf = buf.TrimEnd(",");
       Results.Text = buf;
       ActiveForm = ResultsForm;
   }

}</source>