• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
安安的BLOG
安安目前专注电子商务解决方案^_^
博客园    首页    新随笔    联系   管理    订阅  订阅

Atlas快速体验五(笔记)

范例五 以 Data-binding 与模板建立 Atlas 网頁应用程序

本範例是利用 Atlas 伺服端的控制項 Listview 控制項繫結到資料來源,並將結果顯示在 Listview 控制項的樣板之中。此外這個範例共沒有使用到 Master Page,因為前面曾經說過 Master Page 對 Atlas Frameowrk 技術並非是必要的,只不過借用 Master Page 的優點不必每個 Page 都必須撰寫 Atlas Script 參照,讓程式版面比較清爽;並且由於少了 Master Page 所帶來的佈景主題外觀樣式,故在程式裡面改用了 site.css 檔案來定義外觀,以下為步驟說明:

Step 1:建立 Atlas 伺服器控制項
以下為 Lab5.aspx 程式碼:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Atlas Server Controls Lab</title>
    <link rel="stylesheet" type="text/css" href="site.css" />
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <atlas:ScriptManager id="mgr1" runat="server" />
    
    <atlas:button runat="server" id="fillButton" text="Get URL List">
      <click>
        <actions>
          <atlas:invokeMethodAction target="dataSource1" method="select" />
        </actions>
      </click>
    </atlas:button>
    
    <atlas:dataSource runat="server" id="dataSource1" serviceUrl="~/DataService.asmx" />
    
    <atlas:ListView runat="server" id="listView1" itemtemplatecontrolid="templateItem">
    
      <bindings>
        <atlas:Binding DataContext="dataSource1" DataPath="data" Property="data" />
      </bindings>
      
      <LayoutTemplate>
        <ul runat="server" id="templateItemParent">
          <li runat="server" id="templateItem">
            <strong id="Strong1" runat="server">
                <atlas:label runat="server" id="nameLabel">
                  <bindings>
                    <atlas:binding DataPath="Name" Property="text" />
                  </bindings>
                </atlas:label>
            </strong>
            <br />
            <atlas:hyperlink runat="server" id="companyUrl" >
              <bindings>
                <atlas:binding DataPath="Description" Property="text" />
              </bindings>           
            </atlas:hyperlink>
          </li>
        </ul>
      </LayoutTemplate>
      
      <emptytemplate>No Data</emptytemplate>
    </atlas:ListView>
    
  </div>
  </form>
</body>
</html> 


程序說明:
以上 ListView 控件、数据绑定方式与模板宣告語法,与 ASP.NET 2.0 控件声明的方式非常接近或者說概念相同;而只要是 Server 端的 Atlas 控制項都必須引入 ScriptManager 來做 Script 管理,它是用來管理和加入 Atlas 服务端所必須的 JavaScript。

Step 2:使用 DataService.asmx 网络服务
DataService.asmx 並不須要額外建立,因為 Hands-On 專案模板已包括了這支程式,本程是回傳欲绑定的信息,以下為程序代码:

<%@ WebService Language="C#" Class="SampleDataService" %>

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SampleDataService : DataService {
	static List<SampleRow> _data;
	static int _nextId;
	static object _dataLock = new object();

	private static List<SampleRow> Data 
    {
		get 
        {
			if (_data == null) 
            {
				lock (_dataLock) 
                {
					if (_data == null) 
                    {
						_data = new List<SampleRow>();
						_data.Add(new SampleRow(0, "A. Datum Corporation", 
"http://www.adatum.com")); _data.Add(new SampleRow(1, "Adventure Works",
"http://www.adventure-works.com")); _data.Add(new SampleRow(2, "Alpine Ski House",
"http://www.alpineskihouse.com")); _data.Add(new SampleRow(3, "Baldwin Museum of Science",
"http://www.baldwinmuseumofscience.com")); _data.Add(new SampleRow(4, "Blue Yonder Airlines",
"http://www.blueyonderairlines.com")); _data.Add(new SampleRow(5, "City Power & Light",
"http://www.cpandl.com")); _data.Add(new SampleRow(6, "Coho Vineyard",
"http://www.cohovineyard.com")); _data.Add(new SampleRow(7, "Contoso, Ltd",
"http://www.contoso.com")); _data.Add(new SampleRow(8, "Graphic Design Institute",
"http://www.graphicdesigninstitute.com")); _nextId = 9; } } } return _data; } } [DataObjectMethod(DataObjectMethodType.Delete)] public void DeleteRow(int id) { foreach (SampleRow row in _data) { if (row.Id == id) { lock (_dataLock) { _data.Remove(row); } break; } } } [DataObjectMethod(DataObjectMethodType.Select)] public SampleRow[] SelectRows() { return SampleDataService.Data.ToArray(); } [DataObjectMethod(DataObjectMethodType.Insert)] public SampleRow InsertRow(string organization, string url) { SampleRow newRow; lock (_dataLock) { newRow = new SampleRow(_nextId++, organization, url); _data.Add(newRow); } return newRow; } [DataObjectMethod(DataObjectMethodType.Update)] public void UpdateRow(SampleRow updateRow) { foreach (SampleRow row in _data) { if (row.Id == updateRow.Id) { row.Name =updateRow.Name; row.Description = updateRow.Description; break; } } } }


程序說明:
同樣地,若看不懂上面 DataService.asmx 程式並不重要,只要知道它是將資料回傳給 Atlas ListView 控制項做繫結用途就可以了。

圖 18 Atlas ListView 控制項執行畫面

Web.config 配置项

使用 Atlas Hands-On-Lab VSI 模板時,您可能不見得會注意到在项目角落中有一個隱形人,它就是 Web.config 配置项,與一般的项目配置项不同它裡面加入了 Atlas 运行所必須的相关設定,以下是其配置設定:

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <!--
        The configSections define a section for ASP.NET Atlas
    -->
    <configSections>
        <sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
            <section name="scripts" type="Microsoft.Web.Configuration.ScriptsSection"/>
            <section name="converters" type="Microsoft.Web.Configuration.ConvertersSection"/>
        </sectionGroup>
    </configSections>

    <!--
        atlas.web section defines the script files required for the Atlas framework when used in
        the client
    -->
    <microsoft.web>
        <scripts scriptLibraryPath="~/ScriptLibrary/">
        </scripts>
        <converters>
            <add type="Microsoft.Web.Services.Converters.DateTimeConverter"/>
            <add type="Microsoft.Web.Services.Converters.DataSetConverter"/>
            <add type="Microsoft.Web.Services.Converters.DataRowConverter"/>
            <add type="Microsoft.Web.Services.Converters.DataTableConverter"/>
        </converters>
    </microsoft.web>
    <appSettings/>
    <connectionStrings/>
    <system.web>
      <pages>
          <controls>
              <add namespace="Microsoft.Web" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
              <add namespace="Microsoft.Web.Components" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
              <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
          </controls>
      </pages>
       <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="false">
          <buildProviders>
              <add extension=".script" type="Microsoft.Web.Compilation.ScriptBuildProvider" />
          </buildProviders>
        </compilation>

        <!--
            ASMX is mapped to a new handler so that proxy JavaScripts can also be served
         -->
        <httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>
        </httpModules>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm"/>
            <error statusCode="404" redirect="FileNotFound.htm"/>
        </customErrors>
        -->
    </system.web>
</configuration>

posted @ 2006-02-28 18:40  安安  阅读(387)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3