1.前台代码:
<asp:Repeater ID="OrderList" runat="server" onitemdatabound="OrderList_ItemDataBound"> <ItemTemplate> <div class="item"> <table class="table" style=" border:1px solid #DDCCCC;; border-right:none;" cellspacing="0" cellpadding="0"> <tr><td rowspan="2" colspan="5"><h1>益农乐游农品清单</h1></td><td>发货单号:</td><td colspan="3"></td></tr> <tr><td>时间:</td><td colspan="8"></td></tr> <tr><td >订单号:</td> <td colspan="4"><%#Eval("orderCode")%></td> <td>下单时间:</td> <td colspan="3"><%#Eval("ordertime")%></td></tr> <tr><td >收货人:</td><td><%#Eval("consignee")%></td><td>地址:</td><td colspan="6" style=" text-align:left;"><%#Eval("address")%></td></tr> <tr><td >电话:</td><td colspan="8" style=" text-align:left"><%#Eval("mobile")%></td></tr> <tr><td colspan="9"> </td></tr> <tr><td>序号</td><td colspan="5">农品描述</td><td>单价</td><td>数量</td><td>金额</td></tr> <asp:Repeater runat="server" ID="detailOrder"> <ItemTemplate> <tr><td><%#Eval("rowID")%></td> <td colspan="5" class="tr" style=" text-align:left"><%#Eval("Name")%></td> <td><%#Eval("UnitPrice")%></td> <td><%#Eval("Count")%></td><td> <%#Eval("TotalPrice")%></td></tr> </ItemTemplate> </asp:Repeater> <tr><td class="dd">配送费:</td><td><%#Eval("express")%></td><td class="dd">促销折扣:</td><td colspan="2" class="dd"><%#Eval("perferPrice")%></td><td class="dd">订单金额:</td><td><%#Eval("amount")%></td><td class="dd" style=" ">游游卡支付:</td><td><%#Eval("ka")%></td></tr> <tr><td>已付款:</td><td><%#Eval("resultAmount")%></td><td>应付款:</td><td colspan="6" style="text-align:left;"><%#Eval("resultAmount")%></td></tr> </table> </div> </ItemTemplate> </asp:Repeater>
2.后台代码:
protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { string ids =Request.Params["ids"]; string[] array = ids.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); string newids = string.Join(",", array); InitData(newids); } } public void InitData(string newids) { var _list = odpdbasicBLL.GetModelList(" ID in (" + newids + ")").Select(c => new OrderNode { orderID=c.ID, orderCode = c.OrderCoder, ordertime = c.Created.ToString(), consignee = c.Consignee, mobile = c.Mobile, address =c.Address +"(" +c.PostCode+")", amount = string.Format("{0:.00}",c.Amount), //金额 perferPrice ="未打折" ,//打折 express =c.Express==0?"0.00":string.Format("{0:.00}",c.Express), resultAmount =string.Format("{0:.00}",Convert.ToDouble(c.Amount) -Convert.ToDouble(c.SubPrice) + Convert.ToDouble(c.Express)), yingAmount=c.Status==0?string.Format("{0:.00}",Convert.ToDouble(c.Amount) -Convert.ToDouble(c.SubPrice) + Convert.ToDouble(c.Express)):"0.00", ka="0.00" }).ToList(); OrderList.DataSource = _list; OrderList.DataBind(); } protected void OrderList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rep = e.Item.FindControl("detailOrder") as Repeater;//找到里层的repeater对象 OrderNode rowv = (OrderNode)e.Item.DataItem;//找到分类Repeater关联的数据项 int ID= rowv.orderID; //获取填充子类的orderID int i = 1; var _list = odpddetailBLL.GetModelList("OrderID=" + ID).Select(c => new { rowID=i++, Name=c.Name+"("+c.ProNameStr+")", UnitPrice=c.UnitPrice, TotalPrice=c.TotalPrice, Count=c.Count, }).ToList(); rep.DataSource =_list; rep.DataBind(); } }
3.说明:
因为数据是model类型的所以在
OrderNode rowv = (OrderNode)e.Item.DataItem;//找到分类Repeater关联的数据项
是转成model类型,若是数据是table类型,那么在此就应该是
DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项