FastSpring学习笔记五(Web页面显示)
2007-11-06 11:02
483 查看
一、我们用之前的例子作为基础,现在做一个符合下面条件的查询并显示出来:1、IsActive=1(激活状态)。2、ClassID=参数。3、按CreatedDate和Priority进行降序排列。因此我们在Announcement.hbm.xml中加入我们的搜索信息(为何是加在这里?因为它是使用NHibernate来进行查询的),下面是Announcement.hbm.xml的完成代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="utf-8" ?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<class name="DZ_Portal.App.Model.Announcement,DZ_Portal.App" table="PT_Announcement" lazy="false">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<id name="ItemID" column="ItemID" type="Int32" unsaved-value="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<generator class="native"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</id>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ModuleID" type="Int32" name="ModuleID" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="CreateByUser" type="String" name="CreateByUser" not-null="true" length="50" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="CreatedDate" type="DateTime" name="CreatedDate" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Title" type="String" name="Title" not-null="true" length="100" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="MoreLink" type="String" name="MoreLink" not-null="true" length="150" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ExpireDate" type="DateTime" name="ExpireDate" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Description" type="String" name="Description" not-null="true" length="2147483647" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Frequency" type="Int32" name="Frequency" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="IsActive" type="Int32" name="IsActive" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Priority" type="Int32" name="Priority" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ClassID" type="Int32" name="ClassID" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</class>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<query name="GetAnnouncementsOfClassID">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<![CDATA[from Announcement announcement WHERE announcement.IsActive=1 AND announcement.ClassID=:param1 ORDER BY announcement.CreatedDate DESC,announcement.Priority DESC]]>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</query>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</hibernate-mapping>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--1。HBM映射配置文件中“urn:nhibernate-mapping-2.0 ”需改为“urn:nhibernate-mapping-2.2”
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
2。 <class name="类名,程序集名" table="Archives" >需改为<class name="类名,程序集名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
" table="Archives" lazy="false">,需要添加“lazy="false"”,不然会出现错误:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
he following types may not be used as proxies: xxxxx: method get_CreateDate should be virtual
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
3。Spring.Data.NHibernate程序集变更为:Spring.Data.NHibernate12 (注意:Spring.Data.NHibernate
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
程序集仍然存在,是对NHibernate1.0X的支持,Spring.Data.NHibernate12 为新增的支持NHibernate1.2.0GA的程序集)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
-->
二、查询工作属于业务逻辑层,因为你的业务就是负责显示最新有用的新闻消息,所以你必须要有一个Announcement的逻辑层对象:AnnouncementManager。因此,我们要在Index页面中使用该对象,我们就需要在Index页面创建时创建该对象,因此我们对Index的Spring的配置需要修改,我们打开spring.net_bean_Index.xml看一下,下面是它的所有代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="utf-8" ?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<objects xmlns='http://www.springframework.net'>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- DAO定义-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementDAO" type="DZ_Portal.App.DAL.AnnouncementDAO,DZ_Portal.App" parent="baseDao">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--Manager定义-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementManager" type="DZ_Portal.App.BLL.AnnouncementManager,DZ_Portal.App">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="AnnouncementDAO" ref="AnnouncementDAO"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 事务
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementManagerTrans" parent="BaseTransactionManager">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="Target" ref="AnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="ProxyInterfaces" value="DZ_Portal.App.BLL.IAnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="TransactionAttributes">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<name-values>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add key="TestTransAction*" value="PROPAGATION_REQUIRED,-TransActionException"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</name-values>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</property>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 页面定义 -->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object type="~/Index.aspx" parent="adminPageM">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="AnnouncementManager" ref="AnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--<property name="AnnouncementManager" ref="AnnouncementManagerTrans"/>-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</objects>
解说:我们采用的是属性注入的方式来实现Index页面创建时创建AnnouncementManager,而AnnouncementManager创建的时候又以属性注入的方式来创建AnnouncementDAO。(一个完整的对象是有3层的:分别是:显示层、业务逻辑层、业务实体,现在我们的显示层为Index页面,逻辑层就是AnnouncementManager,我们不能没有业务实体层,因此,创建逻辑层时必须创建业务实体层,而创建业务实体的,正好是这个AnnouncementDAO,它采用工厂模式来生产我们需要的业务实体),这就完整地解释了这个页面的相关配置。(我有个想法,就是,这些不同层的对象基本上都是一起的,如果其它页面需要实现他们时,同样又要定义一次?或者不定义--可以不定义,那样,以后维护的时候会很乱的,我有个想法是把他们放到另一个单元叫:Spring.Net_bean_Announcement,意思是说:Announcement对象的Spring配置,这样就必须在web.config中加入该spring的配置,现在我们暂时不这样做了,就让它这样吧)。
三、查询配置好、查询执行对象已在spring中配置好、现在就要在显示层中使用这些已做好的东西了,我把所有代码列出来,在后面会解说的:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using FastSpring.Web.Base;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using DZ_Portal.App.BLL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using DZ_Portal.App.Model;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class Index : BasePageSession
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_PreInit(Object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DoShowAnnouncements();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Response.Redirect("~/SystemAdmin/fsLogin.aspx", false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID", "101", 0, 10);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
AnnouncementManager#region AnnouncementManager
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private IAnnouncementManager m_AnnouncementManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public IAnnouncementManager AnnouncementManager
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
set
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_AnnouncementManager = value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void DoShowAnnouncements()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID", "101", 0, 10);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WebControlDataBind(this.FSFindControl("FSPagerList"), Announcements);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i = Announcements.Count;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
VL_DataBind#region VL_DataBind
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public virtual void WebControlDataBind(System.Web.UI.Control WebControl, IList DataSource)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if ((WebControl == null) | (DataSource == null))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//没有找到列表显示控件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PrintLog("WebControl is null or DataSource is null");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//根据不同的列表显示控件,进行数据绑下
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//DataGrid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (WebControl is System.Web.UI.WebControls.DataGrid)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.DataGrid _control = WebControl as System.Web.UI.WebControls.DataGrid;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//Repeater
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.Repeater)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.Repeater _control = WebControl as System.Web.UI.WebControls.Repeater;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//DataList
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.DataList)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.DataList _control = WebControl as System.Web.UI.WebControls.DataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//GridView
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.GridView)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.GridView _control = WebControl as System.Web.UI.WebControls.GridView;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
catch ...{ }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
解说:spring属性注入,因此该类中必须有一个相关的对象,我们使用接口的编程模式,定义了这个IAnnouncementManager m_AnnouncementManager接口,并使用该接口对象。好了,我们要在页面初始化的时候显示我们的符合条件的搜索结果,因此我做了个过程:DoShowAnnouncements。DoShowAnnouncements过程分2步完成:1、搜索出数据记录:IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID",
"101", 0, 10);2、数据绑定到页面控件:WebControlDataBind(this.FSFindControl("FSPagerList"), Announcements);(该方法我是参照FastSpring底层的数据绑定方式进行改写的,该方法比较通用,以后会考虑重载或者直接加入底层基类,以方便以后使用)。
四、aspx页面文件的修改,下面是所有代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" MasterPageFile="~/FSMasterPage.master" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" Title="Untitled Page" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server" target="_top" method="post">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<div id="Div_Body" style="overflow-x: auto; width: 776; height: 386px" align="left">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater ID="FSPagerList" runat="server" EnableViewState="true">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ul>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<li><a class="0" href="http://www.163.com" target="_blank">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#DataBinder.Eval(Container.DataItem, "ClassID")%></a>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<a class="0" href="http://www.163.com" target="_blank">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#DataBinder.Eval(Container.DataItem, "Title")%></a>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</li>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ul>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</div>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Content>
解说:我从www.pconline.com.cn中的源码看到,他们是使用div和table相结合的方式来显示,我这里就采用了div来进行显示,有关div和table的页面布局,可以自己去搜索相关的文章(粗略说一下:table是表格,用于显示数据用,div才叫布局,如果整个页面用table布局,那么,它在table结束完它才会显示页面,用户会觉得网站很慢,影响用户的兴致,而采用div布局,它处理数据是从顶部到底部一个个显示出来的,可以在网速慢的情况看一下www.pconline.com.cn的网站就知道原因了,但是sina网站使用table布局,那有它们的原因的,我就不说了,自己可以去搜索相关的资料吧,可以搜索:“div
table 区别”)。WebControlDataBind函数有2个参数,一个是需要绑定的页面控件,一个是数据源,所以,这个aspx页面中有一个Repeater对象的定义:<asp:Repeater ID="FSPagerList" runat="server" EnableViewState="true">,至于这个页面的代码解说,我就不说了,我对html代码也不熟悉,我只是抄过来的哦。大家如果是一步步跟我学的,不知道能否正常运行,我怕有哪些地方遗留忘记说了,因为我也是新手,我还不能很熟悉整个流程,有缺少的地方,不能运行可以告诉我,我再改正一下。
原创作品出自努力偷懒,转载请说明文章出处:http://blog.csdn.net/kfarvid或 http://www.cnblogs.com/kfarvid/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="utf-8" ?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<class name="DZ_Portal.App.Model.Announcement,DZ_Portal.App" table="PT_Announcement" lazy="false">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<id name="ItemID" column="ItemID" type="Int32" unsaved-value="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<generator class="native"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</id>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ModuleID" type="Int32" name="ModuleID" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="CreateByUser" type="String" name="CreateByUser" not-null="true" length="50" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="CreatedDate" type="DateTime" name="CreatedDate" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Title" type="String" name="Title" not-null="true" length="100" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="MoreLink" type="String" name="MoreLink" not-null="true" length="150" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ExpireDate" type="DateTime" name="ExpireDate" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Description" type="String" name="Description" not-null="true" length="2147483647" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Frequency" type="Int32" name="Frequency" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="IsActive" type="Int32" name="IsActive" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="Priority" type="Int32" name="Priority" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property column="ClassID" type="Int32" name="ClassID" not-null="true" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</class>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<query name="GetAnnouncementsOfClassID">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<![CDATA[from Announcement announcement WHERE announcement.IsActive=1 AND announcement.ClassID=:param1 ORDER BY announcement.CreatedDate DESC,announcement.Priority DESC]]>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</query>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</hibernate-mapping>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--1。HBM映射配置文件中“urn:nhibernate-mapping-2.0 ”需改为“urn:nhibernate-mapping-2.2”
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
2。 <class name="类名,程序集名" table="Archives" >需改为<class name="类名,程序集名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
" table="Archives" lazy="false">,需要添加“lazy="false"”,不然会出现错误:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
he following types may not be used as proxies: xxxxx: method get_CreateDate should be virtual
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
3。Spring.Data.NHibernate程序集变更为:Spring.Data.NHibernate12 (注意:Spring.Data.NHibernate
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
程序集仍然存在,是对NHibernate1.0X的支持,Spring.Data.NHibernate12 为新增的支持NHibernate1.2.0GA的程序集)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
-->
二、查询工作属于业务逻辑层,因为你的业务就是负责显示最新有用的新闻消息,所以你必须要有一个Announcement的逻辑层对象:AnnouncementManager。因此,我们要在Index页面中使用该对象,我们就需要在Index页面创建时创建该对象,因此我们对Index的Spring的配置需要修改,我们打开spring.net_bean_Index.xml看一下,下面是它的所有代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<?xml version="1.0" encoding="utf-8" ?>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<objects xmlns='http://www.springframework.net'>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- DAO定义-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementDAO" type="DZ_Portal.App.DAL.AnnouncementDAO,DZ_Portal.App" parent="baseDao">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--Manager定义-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementManager" type="DZ_Portal.App.BLL.AnnouncementManager,DZ_Portal.App">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="AnnouncementDAO" ref="AnnouncementDAO"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 事务
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object id="AnnouncementManagerTrans" parent="BaseTransactionManager">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="Target" ref="AnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="ProxyInterfaces" value="DZ_Portal.App.BLL.IAnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="TransactionAttributes">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<name-values>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add key="TestTransAction*" value="PROPAGATION_REQUIRED,-TransActionException"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</name-values>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</property>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!-- 页面定义 -->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<object type="~/Index.aspx" parent="adminPageM">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<property name="AnnouncementManager" ref="AnnouncementManager"/>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--<property name="AnnouncementManager" ref="AnnouncementManagerTrans"/>-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</object>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</objects>
解说:我们采用的是属性注入的方式来实现Index页面创建时创建AnnouncementManager,而AnnouncementManager创建的时候又以属性注入的方式来创建AnnouncementDAO。(一个完整的对象是有3层的:分别是:显示层、业务逻辑层、业务实体,现在我们的显示层为Index页面,逻辑层就是AnnouncementManager,我们不能没有业务实体层,因此,创建逻辑层时必须创建业务实体层,而创建业务实体的,正好是这个AnnouncementDAO,它采用工厂模式来生产我们需要的业务实体),这就完整地解释了这个页面的相关配置。(我有个想法,就是,这些不同层的对象基本上都是一起的,如果其它页面需要实现他们时,同样又要定义一次?或者不定义--可以不定义,那样,以后维护的时候会很乱的,我有个想法是把他们放到另一个单元叫:Spring.Net_bean_Announcement,意思是说:Announcement对象的Spring配置,这样就必须在web.config中加入该spring的配置,现在我们暂时不这样做了,就让它这样吧)。
三、查询配置好、查询执行对象已在spring中配置好、现在就要在显示层中使用这些已做好的东西了,我把所有代码列出来,在后面会解说的:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Data;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Configuration;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Collections;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.Security;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.WebControls.WebParts;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI.HtmlControls;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using FastSpring.Web.Base;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using DZ_Portal.App.BLL;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using DZ_Portal.App.Model;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public partial class Index : BasePageSession
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_PreInit(Object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!IsPostBack)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DoShowAnnouncements();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void Page_Load(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.Response.Redirect("~/SystemAdmin/fsLogin.aspx", false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID", "101", 0, 10);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
AnnouncementManager#region AnnouncementManager
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private IAnnouncementManager m_AnnouncementManager;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public IAnnouncementManager AnnouncementManager
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
set
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_AnnouncementManager = value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
protected void DoShowAnnouncements()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID", "101", 0, 10);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
WebControlDataBind(this.FSFindControl("FSPagerList"), Announcements);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i = Announcements.Count;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
VL_DataBind#region VL_DataBind
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public virtual void WebControlDataBind(System.Web.UI.Control WebControl, IList DataSource)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if ((WebControl == null) | (DataSource == null))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//没有找到列表显示控件
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PrintLog("WebControl is null or DataSource is null");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//根据不同的列表显示控件,进行数据绑下
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//DataGrid
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (WebControl is System.Web.UI.WebControls.DataGrid)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.DataGrid _control = WebControl as System.Web.UI.WebControls.DataGrid;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//Repeater
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.Repeater)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.Repeater _control = WebControl as System.Web.UI.WebControls.Repeater;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//DataList
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.DataList)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.DataList _control = WebControl as System.Web.UI.WebControls.DataList;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//GridView
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (WebControl is System.Web.UI.WebControls.GridView)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.Web.UI.WebControls.GridView _control = WebControl as System.Web.UI.WebControls.GridView;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataSource = DataSource;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_control.DataBind();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
catch ...{ }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
解说:spring属性注入,因此该类中必须有一个相关的对象,我们使用接口的编程模式,定义了这个IAnnouncementManager m_AnnouncementManager接口,并使用该接口对象。好了,我们要在页面初始化的时候显示我们的符合条件的搜索结果,因此我做了个过程:DoShowAnnouncements。DoShowAnnouncements过程分2步完成:1、搜索出数据记录:IList Announcements = m_AnnouncementManager.FindEntityListByNamedQueryOfRecord("GetAnnouncementsOfClassID",
"101", 0, 10);2、数据绑定到页面控件:WebControlDataBind(this.FSFindControl("FSPagerList"), Announcements);(该方法我是参照FastSpring底层的数据绑定方式进行改写的,该方法比较通用,以后会考虑重载或者直接加入底层基类,以方便以后使用)。
四、aspx页面文件的修改,下面是所有代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...@ Page Language="C#" MasterPageFile="~/FSMasterPage.master" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" Title="Untitled Page" %>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<form id="form1" runat="server" target="_top" method="post">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<div id="Div_Body" style="overflow-x: auto; width: 776; height: 386px" align="left">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<asp:Repeater ID="FSPagerList" runat="server" EnableViewState="true">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<ul>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<li><a class="0" href="http://www.163.com" target="_blank">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#DataBinder.Eval(Container.DataItem, "ClassID")%></a>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<a class="0" href="http://www.163.com" target="_blank">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<%...#DataBinder.Eval(Container.DataItem, "Title")%></a>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</li>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ul>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ItemTemplate>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Repeater>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</div>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</form>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</asp:Content>
解说:我从www.pconline.com.cn中的源码看到,他们是使用div和table相结合的方式来显示,我这里就采用了div来进行显示,有关div和table的页面布局,可以自己去搜索相关的文章(粗略说一下:table是表格,用于显示数据用,div才叫布局,如果整个页面用table布局,那么,它在table结束完它才会显示页面,用户会觉得网站很慢,影响用户的兴致,而采用div布局,它处理数据是从顶部到底部一个个显示出来的,可以在网速慢的情况看一下www.pconline.com.cn的网站就知道原因了,但是sina网站使用table布局,那有它们的原因的,我就不说了,自己可以去搜索相关的资料吧,可以搜索:“div
table 区别”)。WebControlDataBind函数有2个参数,一个是需要绑定的页面控件,一个是数据源,所以,这个aspx页面中有一个Repeater对象的定义:<asp:Repeater ID="FSPagerList" runat="server" EnableViewState="true">,至于这个页面的代码解说,我就不说了,我对html代码也不熟悉,我只是抄过来的哦。大家如果是一步步跟我学的,不知道能否正常运行,我怕有哪些地方遗留忘记说了,因为我也是新手,我还不能很熟悉整个流程,有缺少的地方,不能运行可以告诉我,我再改正一下。
原创作品出自努力偷懒,转载请说明文章出处:http://blog.csdn.net/kfarvid或 http://www.cnblogs.com/kfarvid/
相关文章推荐
- FastSpring学习笔记五(Web页面显示)
- 页面每次添加都显示最后一次访问记录spring scope="prototype" 学习笔记
- OWC学习笔记之web页面显示Excel文件
- mini-web学习笔记之经典CRUD显示页面总结
- 【WPF学习笔记】之如何把数据库里的值读取出来然后显示在页面上:动画系列之(六)(评论处有学习资料及源码)
- springboot学习笔记3(全局错误页面)
- Spring学习笔记之构建Spring Web应用程序
- OAF学习笔记-11-页面传值(传ID,显示为Name)
- OAF学习笔记-11-页面传值(传ID,显示为Name)
- Spring Boot 学习笔记(二)—— WEB相关配置
- FastSpring学习笔记一
- FastSpring学习笔记二(使用工具MyGeneration生成Model和NHibernate的代码 )
- OAF学习笔记-12- 从系统获取ID值,查出Name,在页面显示
- OAF学习笔记-18- Update后页面显示不是最新的数据的解决方法
- OAF学习笔记-18- Update后页面显示不是最新的数据的解决方法
- Spring Web MVC框架学习笔记
- PHP学习笔记-PHP与Web页面的交互2
- Spring Web Flow 学习笔记(2)-流程的组件
- 【selenium学习笔记】webdriver进行页面元素定位
- CSS3与页面布局学习笔记(五)——Web Font与CSS Sprites(又称CSS精灵、雪碧图)技术