ASP.NET: Reusing the same Repeater ItemTemplate
I'm currently using a certain ItemTemplate
for three repeaters t开发者_如何学JAVAhat 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?
No. That's the reason user controls exist, to encapsulate repeating visual components.
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.
精彩评论