Reputation: 59336
I want to implement a very simple list control. It has 2 properties:
The control implementation must render each row using the template specified in RowTemplate
passing the corresponding object in the DataSource
list, so that, if I have a property called Name
in the passed object, it would be accessible with a Eval("Name")
.
I want an example of how to render the control using RowTemplate
and how to pass the correspondent DataSource
object to the template.
I'm reading the MSDN documentation on the subject: Data Binding Expression Overview and Binding to Databases but I just can't find how to implement a control that passes an object to the template.
Upvotes: 0
Views: 745
Reputation: 116977
It sounds like you're trying to develop a templated data-bound control.
Essentially you just need to iterate your datasource object during the rendering of the main control. For each item in your datasource, create a new instance of your template container object and add it to the container control. Depending on what you're extending, the actual render method might vary, but if you're extending something like BaseDataList
, then you would do it in "CreateControlHeirarchy()
".
There's a few walkthroughs around that you can check out. Here's a pretty straightforward one.
Upvotes: 3