关于Reapeter的总结

在aspx文件中操作:
<asp:Repeater ID="ConsultRepeater" runat="server" OnItemDataBound="ConsultRepeater_ItemDataBound">
              <ItemTemplate>
 <%# Eval("Ucontent")%>
    </ItemTemplate>
 </asp:Repeater>
1.在对应的cs文件中,获取每项的数据的方法:
 protected void ConsultRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
   {
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
           Panel replyPanel = e.Item.FindControl("ReplyPanel") as Panel;//找到里层的repeater对象

            DataRowView drv = (DataRowView)e.Item.DataItem; //***
            if (string.IsNullOrEmpty(drv["Response"].ToString()))
            {
                replyPanel.Visible = false;
            }
            else
                replyPanel.Visible = true;
       }
   }

2.多个repeater的嵌套使用:
<asp:Repeater ID="ProductRepeater" runat="server" 
            onitemdatabound="ProductRepeater_ItemDataBound">
            <ItemTemplate>
                <li>
                    <div class="img">
                        <img src='Prod_Images/<%# Eval("Pro_Small_Image") %>' height="100" width="100" />
                    </div>
                    <div class="text">
                        <div class="title">
                            <a href='coupon.aspx?bigcategory=<%# Eval("Pro_Table")%>&proid=<%# Eval("Pro_ID")%>'>
                                <%# Eval("Pro_Name")%></a></div>
                        <div>
                            
                                <asp:Repeater ID="ParamRepeater" runat="server">
                                <ItemTemplate>
                                    <span><%# Eval("Name")%>: <%# Eval("Value")%></span>
                                </ItemTemplate>
                                <AlternatingItemTemplate>
                                    <span class="bar">|</span><span><%# Eval("Name")%>: <%# Eval("Value")%></span>
                                </AlternatingItemTemplate>
                                </asp:Repeater>
                        </div>
                        <div class="footer">
                            <a href='coupon.aspx?bigcategory=<%# Eval("Pro_Table")%>&proid=<%# Eval("Pro_ID")%>'>
                                <asp:Label ID="CityLabel" runat="server" Text=""></asp:Label>共有<span class="digit"><%# Eval("CouponNum")%></span>条优惠</a>
                        </div>
                    </div>
                </li>
            </ItemTemplate>
        </asp:Repeater>
对应的cs文件:
protected void ProductRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,
        //HeaderTemplate,,ItemTemplate,SeparatorTemplate)
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rep = e.Item.FindControl("ParamRepeater") as Repeater;//找到里层的repeater对象
            DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
            string str = Convert.ToString(rowv["Pro_Content"]); //获取填充子类的内容
            rep.DataSource = Product.FillPara(str); //LiftQuestionCtr.GetSomeQuestionsByTypeid(typeid, 2);
            rep.DataBind();
        }
        Label cityLable = e.Item.FindControl("CityLabel") as Label;
        cityLable.Text  = CityDA.GetCurCity();
    }
posted @ 2010-09-13 21:48  大CC  阅读(543)  评论(0编辑  收藏  举报
木书架 大CC的博客