后台代码:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Collections.Generic; using System.Data.SqlClient; public partial class admin_orderdetail : System.Web.UI.Page { ArrayList a = new ArrayList(); int price; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Order(); Bindgr(); } } public void Bindgr() { pronum.Text=Request.QueryString["id"]; BLL.Admin_order order = new BLL.Admin_order(); SqlDataReader dr=order.GetReceiptAddress(pronum.Text); while (dr.Read()) { ordertime.Text = dr["order_date"].ToString(); address.Text = dr["address_detailed_address"].ToString(); mobile.Text = dr["address_tel"].ToString(); mail.Text = dr["address_postalcode"].ToString(); name.Text = dr["address_consignee_name"].ToString(); } dr.Close(); } public void Order() { string orderId = Request.QueryString["id"]; BLL.Admin_order order = new BLL.Admin_order(); List<Model.Admin_Order_Detail> list = order.GetDetail(orderId); count.Text = list.Count.ToString(); for (int i = 0; i < list.Count; i++) { a.Add( list[i].detail_id); } Repeater1.DataSource = list; Page.DataBind(); } protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { for (int i = 0; i < a.Count; i++) { int b = int.Parse(a[i].ToString()); BLL.Admin_order order = new BLL.Admin_order(); List<Model.Admin_Buy_Goods_Attribute> list1 = order.GetAttribute(b); Repeater re = e.Item.FindControl("Repeater2") as Repeater; re.DataSource = list1; re.DataBind(); } } } }
前台代码:
1 <%@ Page Language="C#" MasterPageFile="~/mu.master" AutoEventWireup="true" CodeFile="orderdetail.aspx.cs" Inherits="admin_orderdetail" Title="订单详细信息" %> 2 3 <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content> 4 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 5 <br /> 6 <div style ="font-size :16px; text-align:center ;">订单详细信息</div> 7 <br /> 8 <table width ="100%" style ="text-align :center;"> 9 <tr> 10 <td><div>订单号:<asp:Label ID="pronum" runat="server" Text="Label"></asp:Label></div></td> 11 <td><div>商品总项数:<asp:Label ID="count" runat="server" Text="Label"></asp:Label></div></td> 12 <td><div>订单时间:<asp:Label ID="ordertime" runat="server" Text="Label"></asp:Label></div></td> 13 </tr> 14 <tr> 15 <td><div>商品总价:<asp:Label ID="sumpric" runat="server" Text="Label"></asp:Label></div></td> 16 <td><div>收货人地址:<asp:Label ID="address" runat="server" Text="Label"></asp:Label></div></td> 17 <td><div>收货人手机号码:<asp:Label ID="mobile" runat="server" Text="Label"></asp:Label></div></td> 18 </tr> 19 <tr> 20 <td><div>收货人邮编:<asp:Label ID="mail" runat="server" Text="Label"></asp:Label></div></td> 21 <td><div>收货人姓名:<asp:Label ID="name" runat="server" Text="Label"></asp:Label></div></td> 22 </tr> 23 </table> 24 <br /> 25 <div style ="text-align : center ;"> 26 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"> 27 <ItemTemplate> 28 <div class="mydiv"> 29 <table class="mytable" width="960px"> 30 <tr> 31 <td>商品名称</td> 32 <td>商品价格</td> 33 <td>商品数量</td> 34 <td>商品属性</td> 35 </tr> 36 <tr> 37 <td><%#Eval("product_name") %></td> 38 <td><%#Eval("detail_price") %></td> 39 <td><%#Eval("detail_nums") %></td> 40 <td colspan="2"> 41 <asp:Repeater ID="Repeater2" runat="server"> 42 <ItemTemplate> 43 <div> 44 <%#Eval("Attribute_Key") %> 45 <%#Eval("Attribute_Value") %> 46 </div> 47 </ItemTemplate> 48 </asp:Repeater> 49 </td> 50 </tr> 51 </table> 52 53 </div> 54 </ItemTemplate> 55 </asp:Repeater> 56 </div> 57 <br /> 58 <div style ="text-align :center ;"><asp:Button ID="Button1" runat="server" Text="返回订单列表" /> 59 60 </div> 61 </asp:Content>
Repeater1_ItemDataBound方法中每次找到的repeater2控件永远都是一个,repeater2控件实例并不会因为你repeater1数据的绑定和行数的增加而增加。这里最好的办法是将两个查询合并为一个。如果不行或者不方便repeater2可以不要,直接使用后台代码往前台页面进行输出。