Microsoft.SharePoint.WebCon ...


DVListBox Class (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class DVListBox
    Inherits ListBox
    Implements IDesignerEventAccessor
Visual Basic (Usage)
Dim instance As DVListBox
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public sealed class DVListBox : ListBox, IDesignerEventAccessor
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.BaseDataBoundControl
         System.Web.UI.WebControls.DataBoundControl
           System.Web.UI.WebControls.ListControl
             System.Web.UI.WebControls.ListBox
              Microsoft.SharePoint.WebControls.DVListBox
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Tags :


Community Content

Adam Buenz - MVP
DVListBox

Description

The Microsoft.SharePoint.WebControls.DVListBox class inherits from the System.Web.UI.WebControls.ListBox to create a data source bindable ListBox that allows single or multiple selection as well as the Microsoft.SharePoint.WebControls.IDesignerEventAccessor interface to contract two members, OnDesignerLoad and OnDesignerPreRender. Since the ASP.NET ControlDesigner doesn’t call OnLoad or OnPreRender when requesting control preview generation and OnInit and OnPreRender are both protected, the control designer can’t directly call OnInit and OnPreRender. Therefore the interface is used to circumvent this shortcoming. For DVListBox the design lifecycle is particularly important because this control is exposed through SharePoint Designer.

DVListBox relies primarily on its ListBox class inheritance for a majority of its functionality, however overriding the PerformDataBinding method and the SelectedValue property for full support in SharePoint Designer.

It should be noted that the because of the “DV” prefix on the DVListBox class name this class implies extension of a pre-existing SharePoint or ASP.NET class targeted for Data View (DV) usage.

Usage Scenario

The primary usage of the DVListBox control can be found with SharePoint Designer (SPD). Within the provided “SharePoint Controls” section in the SPD ToolBox, under the “Data View Controls” category the control is represented under the title “DataView ListBox”. Within managed code, the object finds little use since it is sealed so locked for inheritance, and trivial inheritance on the ListBox class provides extension of further object attributes if required. However, use is analogous to any WebControl.

In the below example, MyClass is inheriting from the System.Web.UI.WebControls.WebParts.WebPart class and its CreateChildControls method is being overridden. Following, a new DVListBox object is being created with its ID property being set to something unique. The DVListBox.DataSourceID is set to an ID that represents a separate ObjectDataSource object which has been created with a specified typename and select method and added to the control collection. Following, the DVListBox.DataBind method is called. Subsequently, the hydrated control is being added to the current instance control collection.

C# Code Example

public class MyClass : WebPart
{
protected override void CreateChildControls()
{
ObjectDataSource mySource = new ObjectDataSource("MyType", "SelectMethod");
mySource.ID = "ListDataSource";
Controls.Add(mySource);
DVListBox list = new DVListBox();
list.ID = "ListBox";
list.DataSourceID = "ListDataSource";
list.DataBind();
Controls.Add(list);
base.CreateChildControls();
}
}

VB.NET Code Example

Public Class [MyClass]
Inherits WebPart
Protected Overloads Overrides Sub CreateChildControls()
Dim mySource As New ObjectDataSource("MyType", "SelectMethod")
mySource.ID = "ListDataSource"
Controls.Add(mySource)
Dim list As New DVListBox()
list.ID = "ListBox"
list.DataSourceID = "ListDataSource"
list.DataBind()
Controls.Add(list)
MyBase.CreateChildControls()
End Sub
End Class
Tags :

Page view tracker