Repeater 两层嵌套

View Code
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="Sigil.OutCall.list" %>
2
3 <asp:repeater id="MainRepeater" runat="server" onitemdatabound="MainRepeater_ItemDataBound">
4 <ItemTemplate>
5 <div class="Cont" id="ISL_Cont" >
6 <div class="ScrCont" >
7 <div id="List1" >
8 <!-- 图片列表 begin -->
9 <div class="pic" > <asp:repeater id="ImgRepeater" runat="server">
10 <ItemTemplate>
11
12 <a href="<%# Eval("url")%>" id="shot<%# Eval("productid")%>"><img src=" <%# Eval("filepath")%>" /></a>
13
14 <!-- 图片列表 end -->
15 </ItemTemplate>
16 </asp:repeater></div>
17 </div>
18 <div id="List2">
19 </div>
20 </div>
21 </div>
22 </ItemTemplate>
23 </asp:repeater>

Cs Code
1 using System;
2 using System.Web;
3 using System.Web.UI;
4 using System.Web.UI.WebControls;
5
6 using Sigil.Common;
7 using SigilSoft.Data.SqlClient;
8 using System.Data;
9
10 namespace Sigil.OutCall
11 {
12 public partial class list : System.Web.UI.Page
13 {
14 private Gladiator g = new Gladiator();
15
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 if (!IsPostBack)
19 {
20 bindlist();
21 }
22
23 }
24 //绑定产品
25 private void bindlist()
26 {
27 string sql = @" select p.productid,p.productname,filepath,p.url from product p INNER JOIN attachments a on p.productid = a.itemid where productstate=4 group by p.productid order by p.productid";
28
29 MainRepeater.DataSource = g.GetDataTable(sql, SqlStringFrom.Program);
30 MainRepeater.DataBind();
31 }
32 //绑定图片列表
33 protected void MainRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
34 {
35 //定位里面的Repeater
36 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
37 {
38
39 Repeater imgRepeater = (Repeater)e.Item.FindControl("ImgRepeater");
40 //获取外面Reperter的值
41 DataRowView drv = (DataRowView)e.Item.DataItem;
42 int productid = Convert.ToInt32(drv["productid"]);
43 string sql = @"select p.productid,p.productname,filepath,p.url from product p , attachments a where p.productid = a.itemid and productstate=4 and p.productid=" + productid + "";
44 imgRepeater.DataSource = g.GetDataTable(sql, SqlStringFrom.Program);
45 imgRepeater.DataBind();
46 }
47 }
48 }
49 }

posted @ 2011-03-24 16:25  Ryo  阅读(330)  评论(0编辑  收藏  举报