前台代码:
<table cellpadding="5" cellspacing="0" border="0" width="90">
    <tr>
       <%BindRelatedProducts();%>
       <asp:Repeater ID="rptRelatedProducts" Runat=server>
             <ItemTemplate>                        
                   <td class="mm blue" valign="top"><a href="Show.aspx?PID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>" target=_blank><img src='<%=config.Path%>upload/<%=product.ProductImg%>' border=0 width="90"></a><br>>> <a href="Show.aspx?PID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>" target=_blank><%#DataBinder.Eval(Container.DataItem,"Name")%></a></td>
             <%# showtr((Container.ItemIndex+1).ToString())%>
             </ItemTemplate>
       </asp:Repeater>
   </tr>
</table>
后台代码:
public string showtr(string num)
  {
        string result = "";
        if(int.Parse(num) % 6 == 0)
        {
             result = "</tr><tr>";
        }
        return result;
  }

其实只要设置好repeater的样式即可控制每行显示记录条数

<div class="productList">
    <asp:Repeater ID="Repeater1" runat="server" >
    <HeaderTemplate>
    <ul>
    </HeaderTemplate>
             <ItemTemplate>
               <li>
                 <a href="GoodsToDetails.aspx?goodsid=<%#Eval("GoodsID") %>&goodsname=<%#Eval("GoodsName")%>" target="_blank" >
                                   
                  <img alt="<%#Eval("GoodsName") %> "  src= "<%#DataBinder.Eval(Container.DataItem,"mImageUrl")%>"  width="113px" height="147px">
                </a>
                &nbsp;&nbsp;&nbsp;<p class="product_msg">
                <a target="_blank" title="<%#Eval("GoodsName") %>"  href="GoodsToDetails.aspx?goodsid=<%#Eval("GoodsID") %>&goodsname=<%#Eval("GoodsName")%>"> <%#CutString(Eval("GoodsName").ToString() ,50) %> </a>
                </p>
                <p class="mprice">市场价¥<span><%#Eval("MarketPrice")%></span></p>
                <p class="hprice">售价¥<span><%#Eval("HotPrice")%></span></p>
               </li> 
         </ItemTemplate>
    <FooterTemplate>
    </ul>          
    </FooterTemplate>
    </asp:Repeater>
</div>

样式设置如下:

 .productList{
   border:1px solid #B7B7B7;
   margin:0px;
   width:560px;
   }
  .productList ul{
   margin:0px;
   padding:0px;
   list-style:none;
   }
   .productList li{
   display:inline;
   float:left;
   height:224px;
   margin:10px 12px 20px 0px;
   width:115px;
   list-style:none;
   }

posted on 2010-12-15 23:54  露水丛生  阅读(1642)  评论(0编辑  收藏  举报