ASP.NET Tutorial/Mobile/List
Содержание
Load data from Access database to Mobile:List
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load(Sender as Object, e as EventArgs)
dim objConn as new OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("EmployeeDatabase.mdb;"))
dim objCmd as new OleDbDataAdapter _
("select * from employee", objConn)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "employee")
lNames.DataSource = ds.Tables("employee").DefaultView
lNames.DataBind()
end sub
sub NamePick(Sender as Object, e as ListCommandEventArgs)
lblName.Text = e.ListItem.Text
lblPhone.Text = e.ListItem.Value
ActiveForm = frmPrice
end Sub
</script>
<Mobile:Form id="frmMenu" BackColor="#ccddcc"
runat="server">
<Mobile:Label runat="server" StyleReference="title"
Text="Names" />
<Mobile:List id="lNames" runat="server"
OnItemCommand="NamePick"
DataTextField="FirstName"
DataValueField="FirstName" />
</Mobile:Form>
<Mobile:Form id="frmPrice" BackColor="#ccddcc"
runat="server">
<Mobile:Label id="lblName" runat="server"/>
<Mobile:Label id="lblPhone" runat="server"/>
</Mobile:Form>
Mobile:Label and Mobile:List
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<script runat="server">
sub StockPick(obj as Object, e as ListCommandEventArgs)
lblName.Text = "Price for " + e.ListItem.Text
lblPrice.Text = e.ListItem.Value
ActiveForm = frmPrice
end Sub
</script>
<Mobile:Form id="frmMenu" BackColor="#ccddcc" runat="server" >
<Mobile:Label runat="server" StyleReference="title"
Text="Companies"/>
<Mobile:List runat="server" OnItemCommand="StockPick">
<Item Text="A" Value="5.0" />
<Item Text="B" Value="3.5" />
<Item Text="C" Value="1.4" />
<Item Text="D" Value="1.3" />
</Mobile:List>
</Mobile:Form>
<Mobile:Form id="frmPrice" BackColor="#ccddcc" runat="server" >
<Mobile:Label id="lblName" runat="server"/>
<Mobile:Label id="lblPrice" runat="server"/>
</Mobile:Form>
Mobile List data binding
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CallList" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="MenuForm" runat="server">
<mobile:List id="CustomerList" runat="server" OnItemCommand="ItemCommand">
<DeviceSpecific>
<Choice Argument="wml11" filter="isWML11">
<ItemTemplate>
<mobile:PhoneCall runat="server"
AlternateFormat="{0} at {1}"
PhoneNumber="<%# Eval("Phone") %>"
Text="<%#Eval("CustomerID") %>" />
</ItemTemplate>
</Choice>
</DeviceSpecific>
</mobile:List>
</mobile:form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.ruponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;
public partial class CallList : System.Web.UI.MobileControls.MobilePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet data = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT * FROM customers WHERE companyname LIKE "A%"",
ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString);
adapter.Fill(data, "Customers");
Session["Customers"] = data;
}
DataSet ds = new DataSet();
ds = (DataSet)Session["Customers"];
CustomerList.DataSource = ds.Tables[0];
CustomerList.DataTextField = "companyname";
CustomerList.DataBind();
}
}
Pick List
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="PickList" %>
<%@ 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">
<b>Where do you want to go today?</b>
<mobile:List runat="server" id="Cities" OnItemCommand="List_Click" >
<item Text="Rome" Value="10" />
<item Text="New York" Value="$500" />
<item Text="London" Value="200" />
<item Text="Paris" Value="350" />
<item Text="Sydney" Value="$1200" />
</mobile:List>
</mobile:Form>
<mobile:Form runat="server" id="ResultsForm">
<mobile:Label runat="server" id="Info"/>
</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 PickList : System.Web.UI.MobileControls.MobilePage
{
protected void List_Click(object source, ListCommandEventArgs e)
{
string msg = String.Format("Going to {0} for {1}.",
e.ListItem.Text, e.ListItem.Value);
Info.Text = msg;
ActiveForm = ResultsForm;
}
}