Deniz Dogan
Deniz Dogan

Reputation: 26227

ASP.NET: Reusing the same Repeater ItemTemplate

I'm currently using a certain ItemTemplate for three repeaters that are all on the same page, but they are all bound to different data sources. Is there any way to refactor my web form without using a user control to easily refer to this template so I will only have to define it once?

Upvotes: 6

Views: 1470

Answers (2)

Prashant Lakhlani
Prashant Lakhlani

Reputation: 5806

yes it's possible, create another asp.net control (ascx) that is having a repeater, create a public method that accepts data table (or list or items) and bind the repeater with that, you will probably get this done in 10mins


public void BindData(DataTable dt)
{
    rpt.DataSource = dt;
    rpt.DataBind();
}

It will work if your dt has same column names.

Upvotes: 1

Oded
Oded

Reputation: 498934

No. That's the reason user controls exist, to encapsulate repeating visual components.

Upvotes: 3

Related Questions