Prev | Current Page 841 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

This is achieved through the use of two templates, ResultStatusTemplate
and ResultItemTemplate, which are added to the control if the template structure is not set in
the .aspx page containing the control. To provide implementation of the default templates, the
template classes must implement the ITemplate interface and its InstantiateIn method. The
signature for this method is as follows:
public void InstantiateIn(Control container)
{}
The template is given the container in which to instantiate its controls. In
ResultStatusTemplate, we use InstantiateIn to add a Label control and a LiteralControl,
which represents an HTML break:
public void InstantiateIn(Control container)
{
Label header = new Label();
header.DataBinding +=new EventHandler(BindResultHeader);
container.Controls.Add(header);
LiteralControl lit = new LiteralControl();
lit.Text = "
";
container.Controls.Add(lit);
}
We also map the DataBinding event exposed by the Label control to BindResultHeader. This
allows us to later insert the correct information into our Label control when a data source is
attached to the StatusTemplate of the Result control in its data-binding process. BindResultHeader
uses a help method named GetResultControl, which is able to cast from the Label control
upward to get at the Result control.


Pages:
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853