ASP.NET Tutorial/Mobile/List — различия между версиями

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

Текущая версия на 14:58, 26 мая 2010

Load data from Access database to Mobile:List

   <source lang="csharp">

<%@ 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></source>


Mobile:Label and Mobile:List

   <source lang="csharp">

<%@ 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></source>


Mobile List data binding

   <source lang="csharp">

<%@ 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();
   }

}</source>


Pick List

   <source lang="csharp">

<%@ 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">
       Where do you want to go today?
       <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;
   }

}</source>