I am using ASP.NET Web Forms and i created a custom .ascx user control which represents a Car having properties like Type, Picture and Color.
Now i try to add on user interface this custom control in a repetitive way. Lets say if i have in database 5 cars, then 5 user controls will be render on UI preferable inside an asp control.
I was looking for such a control, studying the grid view, and repeater but they seems to have as data source only lists of objects which are build from “primitive” types not objects like a list of my custom ascx control.
My question is if i can somehow to render those user controls inside a repetitive cycle inside an asp or html control which gives the option to format it (supports css) ? (and if so please provide me an example)
Create a
ListViewwith your user control inside of it, and then bind aList<CarObject>to thatListViewBind a list of your object, such as
List<Car>, to that list view,listView1.DataSource = myListOfCars;. Then in aItemDataBoundevent bind your object to your user control.You could also, alternatively, place the markup from your user control inside of the
ListView, and then bind the information inside of anItemDataBoundevent and sidestep the whole user control issue altogether. This still allows you to reuse the markup.