Tuesday, April 7, 2009

Bind List Items using SPDataSource using the object model

SPDataSource is a control that can be used to access data without needing declarative code


<%@ Register Tagprefix="SPwebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<SPWebControls:SPDataSource runat="server" ID="dsPersonTitles" DataSourceMode="List"
SelectCommand="<Query><OrderBy><FieldRef Name='FirstName' /></OrderBy></Query>"

>

<SelectParameters>
<asp:Parameter Name="WebUrl" DefaultValue="{sitecollectionroot}" />
<asp:Parameter Name="ListName" DefaultValue="Employee" />
</SelectParameters>
</SPWebControls:SPDataSource>

<asp:DropDownList runat="server" ID="ddlPersonTitles" CssClass="title" DataSourceID="dsPersonTitles" DataTextField="FirstName" DataValueField="ID">
</asp:DropDownList>



Parameters

The SPDataSource Inherits from SPDataSourceView, basically a helper class for SPDataSourceView.
After a little Reflector-ing of SPDataSourceView I found these keys it is processing from from the parameter values collection.

  • webid
  • weburl
  • rootfolder
  • listid
  • listname
  • listitemguid
  • listitemid
  • folderid
  • nextpagedata
  • startrowindex
  • maximumrows