Repeater控件
1.Repeater的ItemIndex的前台使用
1 <%# if(Container.ItemIndex<=3){%> 2 <div class="pic"> 3 <a href='Goods.aspx?id=<%#eval_r("ProductId")%>' target="_blank"> 4 <img src='uppic/product-s/<%# eval_r("Pic1")%>' alt="<%# eval_r("ProductName")%>" /></a> 5 </div> 6 <%}else if (Container.ItemIndex<=12){%> 7 8 <div class="t"> 9 <a title='<%# eval_r("ProductName") %>' href='Goods.aspx?id=<%#eval_r("ProductId")%>' target="_blank"> 10 <%# eval_r("ProductName")%> 11 </a><br /> 12 <s>市场价:<%# eval_r("MarketPrice", "{0:F2}")%>元</s><br /> 13 会员价:<%# eval_r("PreferentialPrice", "{0:F2}")%>元<br /> 14 VIP价:<%# eval_r("VipPrice", "{0:F2}")%>元<br /> 15 <%# ShowTradePrice()?"批发价:"+eval_r("TradePrice", "{0:F2}"):""%> 16 <img src="images/btn_buy.gif" onclick="window.open('ShoppingCart.aspx?id=<%# eval_r("ProductId")%>')" class="btn" /> 17 <img src="images/btn_favorite.gif" onclick="window.open('AddFavorite.aspx?id=<%# eval_r("ProductId")%>')" class="btn"/> 18 </div> 19 20 <%} %>
2.前台赋值后台获取
1 前台: 2 <asp:TextBox ID="ItemIndex"........Text="<%#Container.ItemIndex+1%>"/> 3 后台: 4 (this.Repeater1.Items.findcontrol("ItemIndex") as TextBox).Text
3.给Repeater中的控件赋属性

1 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 2 { 3 HtmlControl hc = (HtmlControl)e.Item.FindControl(""); 4 if (e.Item.ItemIndex > 2) 5 { 6 hc.Attributes.Add("style", "color:black"); 7 } 8 }
4.