HierarchicalDataBoundControlAdapter Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Customizes the behavior of a HierarchicalDataBoundControl object with which this control adapter is associated, for specific browser requests.
public ref class HierarchicalDataBoundControlAdapter : System::Web::UI::WebControls::Adapters::WebControlAdapter
public class HierarchicalDataBoundControlAdapter : System.Web.UI.WebControls.Adapters.WebControlAdapter
type HierarchicalDataBoundControlAdapter = class
inherit WebControlAdapter
Public Class HierarchicalDataBoundControlAdapter
Inherits WebControlAdapter
- Inheritance
Examples
The following code example shows how to extend the HierarchicalDataBoundControlAdapter class to render a hierarchical TreeView control that is bound to an XmlDataSource object.
This code example contains four objects:
An adapter derived from the HierarchicalDataBoundControlAdapter class.
The .aspx file that incorporates the TreeView control and device-specific content.
A browser file to link the adapter to a device type.
An XML file that contains a hierarchical list of employees.
This code example consists of four code segments. The first code segment demonstrates how to extend the HierarchicalDataBoundControlAdapter class.
using System;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
namespace Contoso
{
[AspNetHostingPermission(
SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(
SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class HierarchicalTreeViewAdapter :
System.Web.UI.WebControls.Adapters.HierarchicalDataBoundControlAdapter
{
// Return a strongly-typed TreeView control for adapter.
protected new System.Web.UI.WebControls.TreeView Control
{
get
{
return (System.Web.UI.WebControls.TreeView)base.Control;
}
}
// Verify the DataSourceID property is set prior to binding data.
protected override void PerformDataBinding()
{
if (Control.DataSourceID != null)
{
base.PerformDataBinding();
}
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Contoso
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class HierarchicalTreeViewAdapter
Inherits _
System.Web.UI.WebControls.Adapters.HierarchicalDataBoundControlAdapter
' Return a strongly-typed TreeView control for adapter.
Protected Overloads ReadOnly Property Control() As _
System.Web.UI.WebControls.TreeView
Get
Return CType( _
MyBase.Control, _
System.Web.UI.WebControls.TreeView)
End Get
End Property
' Verify the DataSourceID property is set prior to binding data.
Protected Overrides Sub PerformDataBinding()
If (Not Control.DataSourceID Is Nothing) Then
MyBase.PerformDataBinding()
End If
End Sub
End Class
End Namespace
The second code segment demonstrates how to declare a TreeView to bind to an XML data source.
<%@ page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HierarchicalDataBoundControl Adapter</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:TreeView ID="TreeView1"
Runat="server"
DataSourceID="XmlDataSource1">
<DataBindings>
<asp:TreeNodeBinding
DataMember="employees" Text="Employees"/>
<asp:TreeNodeBinding
DataMember="employee" TextField="id" />
<asp:TreeNodeBinding
DataMember="name" TextField="fullname" />
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1"
Runat="server"
DataFile="employees.xml" />
<br />
</form>
</body>
</html>
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HierarchicalDataBoundControl Adapter</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:TreeView ID="TreeView1"
Runat="server"
DataSourceID="XmlDataSource1">
<DataBindings>
<asp:TreeNodeBinding
DataMember="employees" Text="Employees"/>
<asp:TreeNodeBinding
DataMember="employee" TextField="id" />
<asp:TreeNodeBinding
DataMember="name" TextField="fullname" />
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1"
Runat="server"
DataFile="employees.xml" />
<br />
</form>
</body>
</html>
The third code segment shows how to link the TreeView control to the custom adapter for browsers running on Windows CE.
The final code segment provides the XML data that the TreeView control binds to.
Remarks
The HierarchicalDataBoundControlAdapter class adapts the associated HierarchicalDataBoundControl control to modify the default markup or behavior for a specific browser. You can extend the HierarchicalDataBoundControlAdapter class to further customize rendering of the HierarchicalDataBoundControl control.
A HierarchicalDataBoundControl control is bound to a data source and generates its user interface (or child control hierarchy, typically), by enumerating the items in the data source to which it is bound. For more information on hierarchical data-bound controls, see HierarchicalDataBoundControl.
Control adapters are.NET components that manage one or more stages in the life cycle of a control for a specific browser. Extending the HierarchicalDataBoundControlAdapter class provides access to the life-cycle stages of the HierarchicalDataBoundControl control. For more information, see Architectural Overview of Adaptive Control Behavior.
The initial request for an adapter causes the .NET Framework to search for a mapped adapter for the control, given the characteristics of the requesting browser. Browser definition files are used by the HttpBrowserCapabilities class to identify the characteristics of the client browser and map the adapter to the browser type.
Constructors
HierarchicalDataBoundControlAdapter() |
Initializes a new instance of the HierarchicalDataBoundControlAdapter class. |
Properties
Browser |
Gets a reference to the browser capabilities of the client making the current HTTP request. (Inherited from ControlAdapter) |
Control |
Retrieves a strongly typed reference to the HierarchicalDataBoundControl control associated with this HierarchicalDataBoundControlAdapter object. |
IsEnabled |
Gets a value indicating whether the Web control and all its parent controls are enabled. (Inherited from WebControlAdapter) |
Page |
Gets a reference to the page where the control associated with this adapter resides. (Inherited from ControlAdapter) |
PageAdapter |
Gets a reference to the page adapter for the page where the associated control resides. (Inherited from ControlAdapter) |
Methods
BeginRender(HtmlTextWriter) |
Called prior to the rendering of a control. In a derived adapter class, generates opening tags that are required by a specific target but not needed by HTML browsers. (Inherited from ControlAdapter) |
CreateChildControls() |
Creates the target-specific child controls for a composite control. (Inherited from ControlAdapter) |
EndRender(HtmlTextWriter) |
Called after the rendering of a control. In a derived adapter class, generates closing tags that are required by a specific target but not needed by HTML browsers. (Inherited from ControlAdapter) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
LoadAdapterControlState(Object) |
Loads adapter control state information that was saved by SaveAdapterControlState() during a previous request to the page where the control associated with this control adapter resides. (Inherited from ControlAdapter) |
LoadAdapterViewState(Object) |
Loads adapter view state information that was saved by SaveAdapterViewState() during a previous request to the page where the control associated with this control adapter resides. (Inherited from ControlAdapter) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
OnInit(EventArgs) |
Overrides the OnInit(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnLoad(EventArgs) |
Overrides the OnLoad(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnPreRender(EventArgs) |
Overrides the OnPreRender(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
OnUnload(EventArgs) |
Overrides the OnUnload(EventArgs) method for the associated control. (Inherited from ControlAdapter) |
PerformDataBinding() |
Binds the data in the data source of the associated hierarchical data-bound control to the adapter. |
Render(HtmlTextWriter) |
Generates the target-specific markup for the control to which the control adapter is attached. (Inherited from WebControlAdapter) |
RenderBeginTag(HtmlTextWriter) |
Creates the beginning tag for the Web control in the markup that is transmitted to the target browser. (Inherited from WebControlAdapter) |
RenderChildren(HtmlTextWriter) |
Generates the target-specific markup for the child controls in a composite control to which the control adapter is attached. (Inherited from ControlAdapter) |
RenderContents(HtmlTextWriter) |
Generates the target-specific inner markup for the Web control to which the control adapter is attached. (Inherited from WebControlAdapter) |
RenderEndTag(HtmlTextWriter) |
Creates the ending tag for the Web control in the markup that is transmitted to the target browser. (Inherited from WebControlAdapter) |
SaveAdapterControlState() |
Saves control state information for the control adapter. (Inherited from ControlAdapter) |
SaveAdapterViewState() |
Saves view state information for the control adapter. (Inherited from ControlAdapter) |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |