1.5.3 网站主页实现过程
本模块使用的数据表:tb_LeaguerInfo。
1.设计步骤
(1)在网站的根目录下新建一个Web窗体,默认名称为Default.aspx,并且将其作为MasterPage.master母版页的内容页,该过程已经在1.5.2小节中详细讲解,Default.aspx主要用于网站的主页。
(2)在Web窗体的Content区域添加一个Table表格,用于页面的布局。
(3)在Web窗体Content区域的Table中添加6个DataList数据服务器控件,主要用于显示各种类型的部分供求信息。
(4)在添加的6个DataList数据服务器控件中分别添加一个Table,用于DataList控件的布局,并绑定相应的数据。在ASPX页中实现绑定代码如下:
<ItemTemplate> <table align="center" cellpadding="0" cellspacing="0" width="266"> <tr> <td> <span class="hong" style="color: #000000">•<a class="huise" href="ShowLeaguerInfo.aspx?id=<%#DataBinder.Eval(Container.DataItem,"id") %>" target="_blank"><%#DataBinder.Eval(Container.DataItem,"title") %></a></span></td> </tr> <tr style="color: #000000"> <td> <img height="1" src="images/line.gif" width="266" /></td> </tr> </table> </ItemTemplate> |
2.实现代码
在主页Web窗体的加载事件中将各种类型的部分供求信息绑定到DataList控件。实现代码如下:
例程18 代码位置:光盘\TM\01\SIS\ Default.aspx.cs
Operation operation = new Operation(); //声明网站业务类对象 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) //!IsPostBack避免重复刷新加载页面 { //获取前6条分类供求信息 dlZP.DataSource = operation.SelectLeaguerInfo(true, "招聘信息", 6); dlZP.DataBind(); dlPX.DataSource = operation.SelectLeaguerInfo(true, "培训信息", 6); dlPX.DataBind(); dlGY.DataSource = operation.SelectLeaguerInfo(true, "公寓信息", 6); dlGY.DataBind(); dlJJ.DataSource = operation.SelectLeaguerInfo(true, "家教信息", 6); dlJJ.DataBind(); dlWPQG.DataSource = operation.SelectLeaguerInfo(true, "物品求购", 6); dlWPQG.DataBind(); dlWPCS.DataSource = operation.SelectLeaguerInfo(true, "物品出售", 6); dlWPCS.DataBind(); dlQDCD.DataSource = operation.SelectLeaguerInfo(true, "求兑出兑", 6); dlQDCD.DataBind(); dlCL.DataSource = operation.SelectLeaguerInfo(true, "车辆信息", 6); dlCL.DataBind(); } }
|
代码贴士
Page.IsPostBack属性:获取一个值,该值指示该页是否正为响应客户端回发而加载,或者它是否正被首次加载和访问。如果是为响应客户端回发而加载该页,则为true;否则为false。
SelectLeaguerInfo方法:自定义业务层类中方法,用于查询同类型收费到期和未到期供求信息(前N条信息),True显示过期信息,False显示未过期信息。
【责任编辑:
夏书 TEL:(010)68476606】