重复数据的页面展示

一、数据重复展示

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         } 

 

 

     

 

posted @ 2017-12-28 17:16  爱踢两键  阅读(217)  评论(0编辑  收藏  举报