前台显示页面

<h1>常见食物类别</h1>
<ul>
<asp:Repeater runat="server" ID="rptList" OnItemDataBound="rptCategory_ItemDataBound">
<ItemTemplate>
<li>
<a href='ArticleList.aspx?id=<%# Eval("Id") %>'><img src='<%# Eval("ImageUrl") %>' /></a>
<div>
<h4><a href='ArticleList.aspx?id=<%# Eval("Id") %>'><%# Eval("Title") %></a></h4>
<p><asp:Literal ID="ltrDes" runat="server" />...</p>
</div>
</li>
</ItemTemplate>
</asp:Repeater>

</ul>

后台

protected void Page_Load(object sender, EventArgs e) {
Category _category = new Category();
rptList.DataSource = _category.GetCategoryInfoes();
rptList.DataBind();
}


protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e) {
if (e.Item.DataItem != null) {
CategoryInfo categoryInfo = (CategoryInfo)e.Item.DataItem;
Food _food = new Food();


var infoes = _food.GetContentInfoByCategoryId(categoryInfo.Id);
StringBuilder sb = new StringBuilder();

for (int i = 0; i < Math.Min(infoes.Count, 3); i++) {
sb.AppendFormat("<a href='Article.aspx?id={1}'>{0}</a> ", infoes[i].Title, infoes[i].Id);
}


((Literal)e.Item.FindControl("ltrDes")).Text = sb.ToString();
}

}


ArticleList.aspx

<div class="list-list">
<asp:Repeater runat="server" ID="rptList" OnItemDataBound="rptList_ItemDataBound">
<ItemTemplate>

<table>
<tr οnmοuseοver="this.className='current';" οnmοuseοut="this.className='';">
<td class="photo">
<a href='Article.aspx?id=<%# Eval("Id") %>' target="_blank">
<img src='<%# Eval("ImageUrl") %>'></a>
</td>
<td class="title">
<a href='Article.aspx?id=<%# Eval("Id") %>'>
<%# Eval("Title") %></a>
</td>
<td class="rl">
<%# Eval("Hot") %>
</td>
<td class="zl">
100
</td>
<td class="xx">
<a href='Article.aspx?id=<%# Eval("Id") %>' target="_blank">详细资料</a>
</td>
</tr>
</table>

</ItemTemplate>

</asp:Repeater>
</div>

后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bjxmh.Jingci;


public partial class tools_food_ArticleList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
Food food = new Food();
int id = int.Parse(Request.Params["id"]);
rptList.DataSource = food.GetContentInfoByCategoryId(id);
rptList.DataBind();
}


protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e) {
if (e.Item.DataItem != null) {
FoodInfo foodInfo = (FoodInfo)e.Item.DataItem;
}
}
}


Article.aspx

<h1><asp:Literal ID="ltrTitle" runat="server" /></h1>
<asp:Image runat="server" ID="imgFood" width="150" height="130"/> 
<div class="intro">
<h3><asp:Literal ID="ltrFullTitle" runat="server" /></h3>
<p><strong>热量:</strong><span>  <asp:Literal ID="ltrHot" runat="server" />  </span>大卡(每100克)</p>
</div>
<div class="xian"></div>
<div class="renqun">
<strong>适应人群</strong><br />
<asp:Literal ID="ltrRenqun" runat="server" />
</div>

后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bjxmh.Jingci;
using Anylen.Base.SqlServer;
using System.Data.SqlClient;




public partial class tools_food_Article : System.Web.UI.Page
{
Food _food = new Food();
protected void Page_Load(object sender, EventArgs e) {
int id = int.Parse(Request.Params["id"]);
var foodInfo = _food.GetContentInfoById(id);
if (foodInfo != null) {
ltrTitle.Text = foodInfo.Title;
ltrFullTitle.Text = foodInfo.FullTitle;
ltrHot.Text = foodInfo.Hot.ToString();
ltrRenqun.Text = foodInfo.Renqun;


imgFood.ImageUrl = foodInfo.ImageUrl;
}


}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值