views:

78

answers:

1

I want to implement a very simple list control. It has 2 properties:

  1. RowTemplate (ITemplate)
  2. DataSource (IList)

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.

+3  A: 

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.

womp
thank you womp. Now I understand how templated data-bound controls work and managed to implement my own.
Ciwee