快速业务通道

ASP.NET 2.0数据教程之五十八:用ObjectDataSource缓存数据

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-21

像其它文件夹一样,Caching文件 夹里的Default.aspx页面将本系列的文章显示出来。记得用户控件 SectionLevelTutorialListing.ascx提供该功能,设计模式里将其拖到页面上。

ASP.NET 2.0数据教程之五十八:用ObjectDataSource缓存数据

图2:为Default.aspx页面添加用户控件 SectionLevelTutorialListing.ascx

最后,将这些页面添加到 Web.sitemap文件里,特别的,放在“Working with Binary Data” <siteMapNode>:之后:

<siteMapNode title="Caching" url="~/Caching/Default.aspx"
  description="Learn how to use the caching features of ASP.NET 2.0.">
  <siteMapNode url="~/Caching/ObjectDataSource.aspx"
     title="ObjectDataSource Caching"
     description="Explore how to cache data directly from the
       ObjectDataSource control." />
  <siteMapNode url="~/Caching/FromTheArchitecture.aspx"
     title="Caching in the Architecture"
     description="See how to cache data from within the
       architecture." />
  <siteMapNode url="~/Caching/AtApplicationStartup.aspx"
     title="Caching Data at Application Startup"
     description="Learn how to cache expensive or infrequently- changing
      queries at the start of the application." />
  <siteMapNode url="~/Caching/SqlCacheDependencies.aspx"
     title="Using SQL Cache Dependencies"
     description="Examine how to have data automatically expire from the
      cache when its underlying database data is modified." />
</siteMapNode>

完成 Web.sitemap文件的更新后,让我们在浏览器里查看,左边的菜单栏显示caching 章节的文章

ASP.NET 2.0数据教程之五十八:用ObjectDataSource缓存数据

图3:网站地图Site Map包含了Caching章节的文章

第二步:在 Web Page页面里展示产品

本文考察怎样使用ObjectDataSource控件内置 (built-in)的缓存功能。在开始之前,我们首先需要创建一个页面,用一个 ObjectDataSource控件调用ProductsBLL class类获取产品信息,再用GridView控 件展示出来。

首先打开Caching文件夹里的ObjectDataSource.aspx页面。 从工具箱拖一个GridView控件到页面,设置其ID为Products,再从智能标签里选 择将其绑定到一个ObjectDataSource控件,ID为ProductsDataSource。设该 ObjectDataSource使用ProductsBLL class类。

ASP.NET 2.0数据教程之五十八:用ObjectDataSource缓存数据

图4:设置ObjectDataSource控件使用ProductsBLL Class类

在 本页面,我们要创建一个允许编辑的GridView控件,当ObjectDataSource控件里 的缓存数据发生改变时,我们可以通过GridView的界面查看到底会发生什么。在 SELECT标签里选择默认的GetProducts()方法, 但是在UPDATE标签里选择接受 productName, unitPrice 和productID作为输入参数的UpdateProduct()重载方法 。

ASP.NET 2.0数据教程之五十八:用ObjectDataSource缓存数据

图5:在UPDATE标签里选择重载的UpdateProduct()方法

最后, 在INSERT和DELETE标签里选择“(None)”,点完成按钮。一旦完成 “设置数据源向导”,Visual Studio会将ObjectDataSource控件的 OldValuesParameterFormatString属性设置为original_{0}。就像在前面的教程 之16章《概述插入、更新和删除数据》里探讨的一样,该属性要么删除掉,要么 设置为{0},不然的话更新操作会报错。

此外,完成向导后,Visual Studio会将产品的所有数据列添加到GridView控件,将除了ProductName, CategoryName和Unit

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号