开发者

ASP Repeater, split into columns?

Im working on a website written in .net which I have no idea how it works, I have the following code..

<ul id="mega"><li><a href="#">Products</a><div> 
    <asp:Repeater ID="RT_Category" runat="server">
        <ItemTemplate>
            <h2><%# DataBinder.Eval(Container.DataItem, "Category")%></h2>
            <asp:Repeater ID="RT_SubCategory" runat="server" 
                DataSource='<%# DataBinder.Eval(Container.DataItem, "SubCat") %>'>
                <HeaderTemplate><p></HeaderTemplate>
                <ItemTemplate>
                    <a href='<%# DataBinder.Eval(Container.DataItem, "LinkS") %>'>
                    <%# DataBinder.Eval(Container.DataItem, "SubcatName")%></a>
                </ItemTemplate>
                <FooterTemplate></p></FooterTemplate>
            </asp:Repeater>
 开发者_开发知识库       </ItemTemplate>
    </asp:Repeater>
</div></li></ul>

This code outputs a list of product categories, my problem is that it lists them in 1 huge list however, Is it possible to somehow wrap a around every 5 records?


You could try with CSS, inline-block or float: left

<ul id="mega"><li><a href="#">Products</a><div> 
    <asp:Repeater ID="RT_Category" runat="server">
        <ItemTemplate>
         <div style="display: inline-block; width: 25%">
            <h2><%# DataBinder.Eval(Container.DataItem, "Category")%></h2>
            <asp:Repeater ID="RT_SubCategory" runat="server" 
                DataSource='<%# DataBinder.Eval(Container.DataItem, "SubCat") %>'>
                <HeaderTemplate><p></HeaderTemplate>
                <ItemTemplate>
                    <a href='<%# DataBinder.Eval(Container.DataItem, "LinkS") %>'>
                    <%# DataBinder.Eval(Container.DataItem, "SubcatName")%></a>
                </ItemTemplate>
                <FooterTemplate></p></FooterTemplate>
            </asp:Repeater>
          </div>
        </ItemTemplate>
    </asp:Repeater>
</div></li></ul>


The following article may help:

Paging with Repeater control in ASP.NET


Although I have seen examples of getting this to work with a Repeater, none are pretty. I suggest looking at the DataList, which has inbuilt properties to control repeating/columns.

DataList.RepeatColumns Property


Akram's answer is apt for your case. However the repeater does look that nice. I would recommend using datalist for the same as it is more customizable, to output the data even column wise. Kindly refer this link: Showing Multiple Records per Row with the DataList Control

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜