asp:Datalist to a asp:repeater?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 years ago
Hi

I'm quite new to asp.net so just after abit of advice please.
I want to change the homepage products datalist to a repeater so I can use my own way of displaying the data without the tables or the spans and breaks. I have changed the tag, changed the ascx.cs and changed the ascx.designer.cs files.
It still throws an error.

Firstly is this possible? and secondly what else do I need to do to get this to work?

Thanks in advance.

Paul
14 years ago
It is possible to "change the homepage products datalist to a repeater".

Add the following to file: Modules\HomePageProducts.ascx
<asp:Repeater ID="rptrProducts" runat="server" OnItemDataBound="rptProducts_OnItemDataBound">
    <HeaderTemplate>            
    </HeaderTemplate>
    <ItemTemplate>
        <div class="ProductItem">
            <div class="title">
                <asp:HyperLink ID="hlProduct" runat="server" />
            </div>
            <div class="picture">
                <asp:HyperLink ID="hlImageLink" runat="server" />
            </div>
        </div>
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>

You can comment out or delete the DataList (dlCatalog).

---

Edit file: Modules\HomePageProducts.ascx.cs

Update the BindData() function, comment out/delete the data binding to the DataList (dlCatalog) and add the databinding to the Repeater (rptrProducts) -new lines are underlined.
private void BindData()
{
    ProductCollection products = ProductManager.GetAllProductsDisplayedOnHomePage();
    if (products.Count > 0)
    {
        //dlCatalog.DataSource = products;
        //dlCatalog.DataBind();

        rptrProducts.DataSource = products;
        rptrProducts.DataBind();
    }
    else
    {
        this.Visible = false;
    }
}


Change the function signature for dlRelatedProducts_ItemDataBound(...)
FROM
protected void dlRelatedProducts_ItemDataBound(object sender, DataListItemEventArgs e)
TO
protected void rptProducts_OnItemDataBound(object sender, RepeaterItemEventArgs e)

This is for version 1.40 and you will need to recompile the solution.

.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.