Mobile List data binding : List « Mobile « ASP.NET Tutorial






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








23.5.List
23.5.1.Pick List
23.5.2.Mobile:Label and Mobile:List
23.5.3.Load data from Access database to Mobile:List
23.5.4.Mobile List data binding