This topic has not yet been rated - Rate this topic

SimpleQueryControl Class

Represents a query control.

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 class SimpleQueryControl : PickerQueryControlBase
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
SimpleQueryControl
Description

The Microsoft.SharePoint.WebControls.SimpleQueryControl inherits from the Microsoft.SharePoint.WebControls.PickerQueryControlBase web control which is a base web control in both shipped as well as custom picker controls. While the SimpleQueryControl name implies it can issue ambiguous queries, it is intended for data retrieval support for the picker controls in SharePoint.

SimpleQueryControl provides the supporting query structure to build your own picker dialog, tolerating data searches from an arbitrary data source. Coupling this with a classes inheriting from PickerDialog and EntityEditorWithPicker allows you to build all the elements of an inclusive custom picker dialog.

SimpleQueryControl relies heavily on the PickerQueryControlBase derivation, extending it to provide search faculties by checking the ViewState for the column names being searching. The ViewState query results are subsequently used when reconstructing column representation to order to support proper data retrieval and display.

The Usage Scenario

The most frequent use of SimpleQueryControl, as implied in the above, is when constructing a complete custom picker dialog. This requires building sister classes inheriting from EntityEditorWithPicker and PickerDialog class to complete the necessary component requirements. PickerQueryControlBase provides two important methods to override, IssueQuery and PickerEntity. IssueQuery is responsible for the data harvesting, in the below setting the PickerDialog.Results property to the current list context after exposure as a DataTable. As well, we are overriding PickerEntity in order to strongly type the returned data. 

It should be noted the use of the types expected. A System.Data.DataTable in IssueQuery is used when setting the PickerDialog.Results, and System.Data.DataRow in GetEntity when strongly typing. This is why the SPList object is being exposed using SPList.GetDataTable. 

C# Code Example

protected override int IssueQuery(string search, string groupName, int pageIndex, int pageSize)
{
DataTable listTable = SPContext.Current.List.GetDataTable();
PickerDialog.Results = listTable;
PickerDialog.ResultControl.PageSize = listTable.Rows.Count;
return listTable.Rows.Count;
}
public override PickerEntity GetEntity(DataRow dr)
{
PickerEntity entity = new PickerEntity();
entity.DisplayText = dr["YourDisplayText"];
entity.Key = dr["YourDisplayText"];
entity.Description = dr["YourDescriptionText"];
entity.IsResolved = true;
return entity;
}

Visual Basic .NET Code Example

Protected Overloads Overrides Function IssueQuery(ByVal search As String, ByVal groupName As String, ByVal pageIndex As Integer, ByVal pageSize As Integer) As Integer
Dim listTable As DataTable = SPContext.Current.List.GetDataTable()
PickerDialog.Results = listTable
PickerDialog.ResultControl.PageSize = listTable.Rows.Count
Return listTable.Rows.Count
End Function

Public Overloads Overrides Function GetEntity(ByVal dr As DataRow) As PickerEntity
Dim entity As New PickerEntity()
entity.DisplayText = dr("YourDisplayText")
entity.Key = dr("YourDisplayText")
entity.Description = dr("YourDescriptionText")
entity.IsResolved = True
Return entity
End Function