All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP编写网站程序的十个经验技巧_php资料_编程技术
delphi设置提示信息
数据库连接URL中分号引发的错误_.net资料_编程技术
Asp.net,Ajax,学习笔记2,UpdatePanel的使用(上)_[Asp.Net教程]
PHP解释器的代码高亮输出_[PHP教程]
ASP.NET开发经验(4):种简便地同时使用匿名与集成,Windows,验证的方法_[Asp.Net教程]
PHP实现任意字符集下正常显示网页的方法_php资料_编程技术
ASP.NET技巧:字符自动截取问题_.net资料_编程技术
总结:关于ASP.NET,2.0一些简单而有用的技巧_.net资料_编程技术
HTML语言剖析(八)表单标记_[Html教程]
Reading number is top 10 pictures
Absolutely shocked. National geographic 50 animal photographys1
赵惟依写真1
各种囧况!玩游戏最不喜欢出现的十件事
世界五大海盗
The money of more than 100 countries and regions22
Summer is most suitable for young people to travel in China2
Exquisite decoration is not paying too much1
恶搞漫画1
含苞欲放的素颜美少女1
The money of more than 100 countries and regions14
Download software ranking
变速齿轮3.26
双旗镇刀客B
Unix video tutorial14
在线棋牌游戏3.05版
塘西风月痕
C++教程第四版
Tram sex maniac 2 (H) rar bag8
软件工程思想
Be there or be square
dreamweaver8中文版
delv published in(发表于) 2014/1/6 8:48:43 Edit(编辑)
ASP.NET,Atlas,ListView显示列表数据_[Asp.Net教程]

ASP.NET,Atlas,ListView显示列表数据_[Asp.Net教程]

ASP.NET Atlas ListView显示列表数据_[Asp.Net教程]

在目前的大部分Web程序中,我们都需要显示给用户一些列表数据。ASP.NET中的GridView服务器控件提供了这种功能,Atlas中的客户端控件ListView也可以在客户端提供类似功能,并以AJAX方式运行。虽然您可以使用传统的GridView控件加上Atlas的UpdatePanel提供同样的AJAX运行方式,但是这种实现方式较低效,也不是“纯粹”的Atlas方法。推荐的方法是采用Atlas的客户端控件ListView来代替。不要担心,Atlas的ListView控件和GridView一样简单,而其二者在很多概念方面是相似的,例如ItemTemplate。但是需要注意的是目前IDE中并没有提供对Atlas脚本的智能感知功能,加之Atlas脚本也没有编译时期检查,所以在书写代码的时候应该格外小心。

  使用ListView的时候应该提供给其一些必要的模版(Template),以告诉Atlas应该如何渲染您的内容。ListView中有如下模版:


  1. layoutTemplate:这个模版用来渲染包含列表项目的容器(例如使用 <table>标记),列表的头部(例如使用 <thead>标记),尾部等。您必须为ListView指定一个layoutTemplate。而且这个模版必须包含一个itemTemplate模版,也可选包含一个separatorTemplate模版。
  2. itemTemplate:这个模版用来渲染列表中的一个项目(例如使用 <tr>标记)。这个模版必须被置于layoutTemplate中。
  3. separatorTemplate:这个模版用来渲染列表中的项目之间的分隔元素(例如使用 <hr>标记)。这个模版必须被置于layoutTemplate中。
  4. emptyTemplate.:这个模版用来渲染没有项目存在时的ListView。此时可能与该ListView相关的DataSource对象中没有项目,或是正在从服务器中取得的过程中。
  ListView中还有一些属性:


  1. itemCssClass:指定项目条目的css class。
  2. alternatingItemCssClass:指定间隔的项目条目的css class。
  3. selectedItemCssClass:指定被选中的项目条目的css class。
  4. separatorCssClass:指定分隔元素的css class。
  5. itemTemplateParentElementId:这个属性指定了itemTemplate和separatorTemplate的父元素。这样itemTemplate和separatorTemplate元素就可以在其中被重复渲染。
  ListView还有一些继承于Sys.UI.Data.DataControl基类的方法/属性,因为在下面的代码中我们不需要使用,这里暂且略过。如果您感兴趣。OK,让我们通过一个实例来说明如何使用ListView控件:

  首先,我们编写一个返回.NET中DataTable的Web Service。注意到在这里将继承于Microsoft.Web.Services.DataService基类,并且为service方法加上定义在名称空间System.ComponentModel中的属性DataObjectMethod。在service方法的开头,我们使用System.Threading.Thread.Sleep(2000)来模拟2秒钟的网络延迟,以便可以看到emptyTemplate中的内容。

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
onclick="this.style.display='none'; Codehighlighter1_171_778_Open_Text.style.display='none'; Codehighlighter1_171_778_Closed_Image.style.display='inline'; Codehighlighter1_171_778_Closed_Text.style.display='inline';" src="/upfiles/2006-4/200642118321889360.gif" align=top>onclick="this.style.display='none'; Codehighlighter1_171_778_Closed_Text.style.display='none'; Codehighlighter1_171_778_Open_Image.style.display='inline'; Codehighlighter1_171_778_Open_Text.style.display='inline';" src="/upfiles/2006-4/200642118321947893.gif" align=top>public class MyService : Microsoft.Web.Services.DataService {

[DataObjectMethod(DataObjectMethodType.Select)]
public DataTable GetListData()
onclick="this.style.display='none'; Codehighlighter1_265_776_Open_Text.style.display='none'; Codehighlighter1_265_776_Closed_Image.style.display='inline'; Codehighlighter1_265_776_Closed_Text.style.display='inline';" src="/upfiles/2006-4/200642118322176677.gif" align=top>onclick="this.style.display='none'; Codehighlighter1_265_776_Closed_Text.style.display='none'; Codehighlighter1_265_776_Open_Image.style.display='inline'; Codehighlighter1_265_776_Open_Text.style.display='inline';" src="/upfiles/2006-4/200642118322191744.gif" align=top> {
System.Threading.Thread.Sleep(2000);

DataTable dt = new DataTable("MyListData");
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Email", typeof(string));
DataRow newRow;
for (int i = 0; i < 5; ++i)
onclick="this.style.display='none'; Codehighlighter1_538_751_Open_Text.style.display='none'; Codehighlighter1_538_751_Closed_Image.style.display='inline'; Codehighlighter1_538_751_Closed_Text.style.display='inline';" src="/upfiles/2006-4/200642118322654992.gif" align=top>onclick="this.style.display='none'; Codehighlighter1_538_751_Closed_Text.style.display='none'; Codehighlighter1_538_751_Open_Image.style.display='inline'; Codehighlighter1_538_751_Open_Text.style.display='inline';" src="/upfiles/2006-4/200642118322644484.gif" align=top> {
newRow = dt.NewRow();
newRow["Name"] = string.Format("Dflying {0}", i);
newRow["Email"] = string.Format("Dflying{0}@dflying.net", i);
dt.Rows.Add(newRow);
}
return dt;
}
}

  然后,添加一些ASP.NET页面中必须的控件/标记:

<atlas:ScriptManager ID="ScriptManager1" runat="server" />
<!-- Element for myList (container) -->
<div id="myList"> </div>
<!-- Layout Elements -->
<div style="display: none;">
</div>

  在上面的标记中,我们加入了三个标记:一个必须的ScriptManager控件。一个id为myList的div,用来让Atlas把渲染后的ListView放置于这里。一个隐藏的div,用于定义我们的模版。这个隐藏div中的元素在页面上是不可见的,只是用来提供给Atlas必要的模版。

  我们在这个隐藏的div中加入如下ListView的模版:

<!-- Layout Template -->
<table id="myList_layoutTemplate" border="1" cellpadding="3">
<thead>
<tr>
<td> <span>No. </span> </td>
<td> <span>Name </span> </td>
<td> <span>Email </span> </td>
</tr>
</thead>
<!-- Repeat Template -->
<tbody id="myList_itemTemplateParent">
<!-- Repeat Item Template -->
<tr id="myList_itemTemplate">
<td> <span id="lblIndex" /> </td>
<td> <span id="lblName" /> </td>
<td> <span id="lblEmail" /> </td>
</tr>
<!-- Separator Item Template -->
<tr id="myList_separatorTemplate">
<td colspan="3">Separator </td>
</tr>
</tbody>
</table>
<!-- Empty Template -->
<div id="myList_emptyTemplate">
No Data
</div>

  上面的代码中您可以看到我提到的所有四种模版。另外还要指定每一个模版一个id,将用于下面的Atlas脚本声明中。在这个例子中我将以HTML Table的形式渲染这个ListView,很抱歉分隔元素将会很丑陋(一个空行)。

  最后在页面中添加Atlas脚本声明:

<dataSource id="listDataSource" autoLoad="true" serviceURL="MyService.asmx" />

<listView id="myList" itemTemplateParentElementId="myList_itemTemplateParent">
<bindings>
<binding dataContext="listDataSource" dataPath="data" property="data" />
</bindings>
<layoutTemplate>
<template layoutElement="myList_layoutTemplate" />
</layoutTemplate>
<itemTemplate>
<template layoutElement="myList_itemTemplate">
<label id="lblIndex">
<bindings>
<binding dataPath="index" transform="Add" property="text"/>
</bindings>
</label>
<label id="lblName">
<bindings>
<binding dataPath="Name" property="text" />
</bindings>
</label>
<label id="lblEmail">
<bindings>
<binding dataPath="Email" property="text" />
</bindings>
</label>
</template>
</itemTemplate>
<separatorTemplate>
<template layoutElement="myList_separatorTemplate" />
</separatorTemplate>
<emptyTemplate>
<template layoutElement="myList_emptyTemplate"/>
</emptyTemplate>
</listView>

  这里我添加了一个Atlas客户端DataSource对象以从Web Service中取得数据。这里我们暂且不多谈DataSource(可能在后续文章中有所介绍)。让我们来看一下ListView相关的定义:在ListView的定义中,我们指定了itemTemplateParentElementId属性。然后在ListView的内部定义了一个binding段,用来把DataSource中取得的数据与这个ListView绑定起来。我们还定义了四个模版段,每个模版段都用layoutElement与上面定义过的四种模版关联。注意到在layoutTemplate模版中的第一个label控件,我们在其绑定中指定了一个Add transformer以将从0开始的顺序变为从1开始(关于Atlas Transformer,请参考我的这篇文章:http://dflying.cnblogs.com/archive/2006/04/05/367908.html)。

  大功告成,运行一下吧。

  装载中:



装载完成:


作者:Dflying Chen 来源:博客园





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.