<asp:DataList ID="dlProduct" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" CellSpacing="0"   CellPadding="0"   Width="600px" OnItemDataBound="dlProduct_ItemDataBound">
                        <ItemStyle/>
                        <ItemTemplate>
                            <table  border="0" id="tbProduct" runat="server" style="height:250px;width:200px" cellpadding="2" cellspacing="0" >
                                <tr>
                                    <td></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:DataList>
我实现的是每行均匀排列3个产品,如果我将table的宽设置为100%,那产品数量大于3个时就变得有宽有窄的(2个能均匀排列),如果我将其设置为固定宽度200px,那么产品数量小于3时又不均匀了,看看大家又没有什么好办法,使得各种情况都完美

解决方案 »

  1.   

    <table  border="0" id="tbProduct" runat="server" style="height:250px;width:200px" cellpadding="0" cellspacing="0" > 
    <asp:DataList ID="dlProduct" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" CellSpacing="0"  CellPadding="0"  Width="600px" OnItemDataBound="dlProduct_ItemDataBound"> 
                            <ItemStyle/> 
                            <ItemTemplate> 
                                    <tr> 
                                        <td> </td> 
                                    </tr>                            
                            </ItemTemplate> 
                        </asp:DataList></table> 你这样子试试看
      

  2.   

    这样应该不行,结构好像不对,table的宽比DataList 的还小
      

  3.   

    table为height:250px;width:200px,设置DataList属性让内容左对齐,不要设置DataList高度,不然当内容没达到设置的高度的时候会垂直居中的
      

  4.   

    自己调好了,谢谢楼上的关注 <asp:DataList ID="dlProduct" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" CellSpacing="0"  CellPadding="0"  Width="600px" OnItemDataBound="dlProduct_ItemDataBound"> 
                            <ItemStyle Width="30%"/> 
                            <ItemTemplate> 
                                <table  border="0" id="tbProduct" runat="server" style="height:250px;width:100%" cellpadding="2" cellspacing="0" > 
                                    <tr> 
                                        <td> </td> 
                                    </tr> 
                                </table> 
                            </ItemTemplate> 
                        </asp:DataList>