动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP.NET技巧 ]的信息

本月文章推荐
.何时.NET中AppDomain会回收? .
.如何让.Net控件在设计时Initiali.
.ASP.NET2.0下为GridView添加服务.
.在存储过程中实现分页.
.ASP.NET技术获取IP与MAC地址的方.
.数据岛出到Excel最为简易的方法.
..net 后台的小偷程序.
.部署安装时写入SQL SERVER和Web..
.在Visual Studio 2005和ASP.NET .
.ASP.NET中用哪种方式表格化数据.
..NET在SQL Server中的图片存取技.
.google的分析(analytics)js代码分.
.如何实现无刷新的DropdownList联.
.安装好.net之后如何运行asp.net程.
.ASP.NET无限分类.
.通过数据捆绑将数据添加到ASP.NE.
.Asp.net取得页面执行时间的代码 .
.结合JavaScript与ASP.NET Web窗体.
.asp.net 2.0 与1.1 在生成的前台.
.asp.net 1.1/ 2.0 中快速实现单点.

使用ASP.NET Atlas ListView控件显示列表数据

发表日期:2006-4-9 |


English Version: http://dflying.dflying.net/1/archive/113_display_listible_data_using_aspnet_atlas_listview_control.html

在这个系列中,我将介绍一些Atlas Sys.UI.Data中较高级的控件,包括:

Sys.UI.Data.ListView:使用ASP.NET Atlas ListView控件显示列表数据
Sys.UI.Data.ItemView:待续
Sys.UI.Data.DataNavigator:待续
Sys.UI.Data.XSLTView:待续
这篇是其中的第一篇:使用ASP.NET Atlas ListView控件显示列表数据

在目前的大部分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中有如下模版:

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

itemCssClass:指定项目条目的css class。
alternatingItemCssClass:指定间隔的项目条目的css class。
selectedItemCssClass:指定被选中的项目条目的css class。
separatorCssClass:指定分隔元素的css class。
itemTemplateParentElementId:这个属性指定了itemTemplate和separatorTemplate的父元素。这样itemTemplate和separatorTemplate元素就可以在其中被重复渲染。
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)]
public class MyService  : Microsoft.Web.Services.DataService {

    [DataObjectMethod(DataObjectMethodType.Select)]
    public DataTable GetListData()
    {
        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)
        {
            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)。

大功告成,运行一下吧。

 

上一篇:.NET 2.0 泛型在实际开发中的一次小应用 人气:5164
下一篇:如何让.Net控件在设计时InitializeComponent()中不生成相关代码 人气:6039
浏览全部ASP.NET的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-9-7 Pcook cms 文章管理系统 (老Y CM
2008-9-6 Movie34电影搜索引擎 v3.0
2008-9-6 wap2.0仿帝国建站喜用 v2.0
2008-9-6 免费人才招聘网 宽屏版 v3.01
2008-9-6 喜喔喔视频采集程序 v1.0 beta
2008-9-6 ASP客户管理系统
2008-9-6 主流驿站中秋祝福程序
2008-9-6 php实现msn协议的类
2008-9-5 Coppermine Photo Gallery v1.4.
2008-9-7 iBlacklist通话黑名单汉化破解补
2008-9-7 EndlessWalls无尽壁纸 v1.0.4破解
2008-9-7 Dynolicious车载测量仪v1.1破解版
2008-9-7 iVoodoo巫毒娃娃1.0.1破解版
2008-9-7 iWallpape精品墙纸1.2破解版
2008-9-7 iChillout自然音效工具1.1破解版
2008-9-7 Todo计划提醒1.2破解版
2008-9-7 allRadio电台集合1.01破解版
2008-9-7 My Money个人理财1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵