This topic has not yet been rated - Rate this topic

DVListBox Class

Represents a ListBox component for a data view.

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

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class DVListBox : ListBox, 
	IDesignerEventAccessor
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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
 
Adam Buenz
SharePoint Services MVP - http://www.sharepointsecurity.com