ASP.NET: reuse of the same ItemTemplate repeater

I am currently using a specific ItemTemplate for three repeaters that are on the same page, but they are all associated with different data sources. Is there a way to reorganize my web form without using a user control to easily reference this template, so I only need to define it once?

+4
source share
2 answers

yes, maybe create another asp.net control (ascx) that has a repeater, create a public method that takes a data table (or list or items) and associates a repeater with this, you will probably do it in 10mins

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

It will work if your dt has the same column names.

+1
source

Not. That a user control exists is to encapsulate repetitive visual components.

+3
source

Source: https://habr.com/ru/post/1303811/


All Articles