ASP.NET Tutorial/Mobile/SelectionList
Версия от 15:30, 26 мая 2010; (обсуждение)
Selection List
<%@ 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?<br />
<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;
}
}