重复数据的页面展示

一、数据重复展示

1、Repeater:最好,不生成任何冗余代码,使用稍麻烦

2、GridView:(生成table冗余代码)

3、DataList:比GridView稍好,也有冗余代码

                       

 1 <%@ Page Title="" Language="C#" MasterPageFile="~/Adminhyl/Adminhyl.Master" AutoEventWireup="true"
 2     CodeBehind="DishesManager.aspx.cs" Inherits="HotelWebProject.Adminhyl.DishesManager" %>
 3 
 4 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 5     <link href="../../Styles/Dishes.css" rel="stylesheet" type="text/css" />
 6 </asp:Content>
 7 <asp:Content ID="Content2" ContentPlaceHolderID="cphMain" runat="server">
 8     <div id="dishcategory">
 9         菜品分类:<asp:DropDownList ID="ddlCategory" runat="server" CssClass="btncss">
10         </asp:DropDownList>
11         &nbsp;<asp:Button ID="btnQuery" CssClass="btncss" runat="server" Text="提交查询"  />
12     </div>
13     <div id="dishlistdiv">
14 
15 
16         <%--1、拖放repeater控件,2、手动添加列模板ItemTemplate,3、静态部分先放进去;4、绑定数据(窗口中显示数据绑定就没问题)--%>
17         <asp:Repeater ID="rptList" runat="server">
18 
19             <ItemTemplate>  
20         <div class="dishlist-item">
21             <div class="dishlist-img">
22                    <%--eval()只适合于查询,如果要修改bander,但不灵活--%>
23                 <img src='<%#Eval("DishId", "/Images/dish/{0}.png") %>'    alt="" />
24             </div>
25             <div class="dishlist-txt">
26                 菜品名称:<%#Eval("DishName") %></div>
27             <div class="dishlist-txt">
28                 菜品分类:<%#Eval("CategoryName") %></div>
29             <div class="dishlist-txt">
30                 菜品价格:¥<%#Eval("UnitPrice") %></div>
31             <div class="dishlist-txt">
32                 <%--修改按钮返回到菜品发布页面,Operation修改时是1;添加时是0--%>
33                 <a href='/Adminhyl/Dishes/DishesPublish.aspx?Operation=1&dishId=<%#Eval("DishId") %>'>修改</a>&nbsp;&nbsp;
34                 <a href="#">删除</a>
35             </div>
36         </div>
37             </ItemTemplate>
38 
39         </asp:Repeater>
40 
41 
42     </div>
43 </asp:Content>

二、分类下拉框的编写

 1         protected void Page_Load(object sender, EventArgs e)
 2         {
 3             if (!IsPostBack)
 4             {
 5                 DAL.DishService  objService=new DAL.DishService();
 6                 //初始化菜品下拉框
 7                 this.ddlCategory.DataValueField = "CategoryId";
 8                 this.ddlCategory.DataTextField = "CategoryName";
 9                 this.ddlCategory.DataSource = objService.GetAllCategory();
10                 this.ddlCategory.DataBind();
11                  //显示所有菜品
12                 this.rptList.DataSource = objService.GetDishes(null);
13                 this.rptList.DataBind();
14             }
15         }

三、查询按钮的编写

 1         /// <summary>
 2         /// 根据菜品编号查询
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         protected void btnQuery_Click(object sender, EventArgs e)
 7         {
 8             this.rptList.DataSource = new DAL.DishService().GetDishes(this.ddlCategory.SelectedValue.ToString());
 9             this.rptList.DataBind();
10         } 

 

 

     

 

转载于:https://www.cnblogs.com/atlj/p/8136730.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值