In these last posts, we’ve already met several of the events generated by the DataView control. I thought it would be a good idea to write a small post which documents many of the events we’ve seen in the past:
command: fired when a user clicks over an element which has been “marked” with the sys:command system attribute;
- rendering: this event is generated when the DataView control is about to start instantiating its template to get the rendered HTML. Any function which handles this event receives two parameters: the first, references the DataView control which generated the event; the second is an instance of the Sys.Data.DataEventArgs type.;
- rendered: marks the end of the HTML rendering process. Functions configured as handlers receive two parameters: the first, references the DataView which generated the event; the second, is an instance of the Sys.DataDataEventArgs type;
- itemRendering: event that is generated before each item’s template instantiation. We can do several interesting things here, like changing the default template or influencing the data that is going to be used during the template instantiation;
- itemRendered: event which signals the end of the instantiation of a template. We’ve seen how we can use this event to customize the generated HTML for an item.
The Sys.Data.DataEventArgs object used by the rendering and rendered events introduces some interesting properties:
- data: references the items that will be used for instantiating the templates;
- itemPlaceholder: used for identifying the place holder where the template’s generated HTML will be put;
- itemTemplate: reference to the template used for instantiating all the elements.
During the rendering event, you can set all of these properties and influence the HTML generated by the DataView control.
Besides these events, there are still others, but we’ll leave them for the next posts because they’re related with the integration of the DataView control with data contexts. Stay tuned for more on MS AJAX.