Tag Archives: SPDatasource

SharePoint SPDataSource

Tired of writing codes and creating webparts? Here is a less code solution for SharePoint developers.

The SPDataSource control (Microsoft.SharePoint.WebControls.SPDataSource) means a lot to developers.

With less custom code one can quickly retrieve and display data from SharePoint lists and libraries.

This is how you can access list data from SharePoint. For select command you can use CAML query builder from U2U.

This data source can be used like a SQL data source which comes with standard asp.net controls.

<SharePoint:SPDataSource ID=”spdsSupervisor” runat=”server” DataSourceMode=”List” SelectCommand=”<Query><Where><Eq><FieldRef Name=’Heading’ /><Value Type=’Choice’>Questions</Value></Eq></Where></Query>”>

<asp:Parameter Name=”ListName” DefaultValue=”Feedback”/>


For data binding to any data bound controls this data source can be used. Given below is an example of using Data source with an asp grid view.

<asp:GridView runat=”server” id=”gvSupervisor” AutoGenerateColumns=”False” DataSourceID=”spdsSupervisor”
GridLines=”None” ForeColor=”#333333″ CellPadding=”4″ width=”100%”>

<FooterStyle BackColor=”#e2eeff” Font-Bold=”True” ForeColor=”White” />

<RowStyle BackColor=”#EFF3FB” Font-Size=”Smaller”/>


<asp:boundfield DataField=”Title” HeaderText=”Type” HeaderStyle-Font-Bold=”true” HeaderStyle-Font-Names=”verdana” HeaderStyle-ForeColor=”#525252″


<asp:templatefield HeaderText=”Rating”


    <asp:RadioButtonList runat=”server” id=”rblCourse”
RepeatDirection=”Horizontal” CssClass=”ms-radiotext”>











<PagerStyle HorizontalAlign=”Center” BackColor=”#2461BF”
ForeColor=”White” />

<SelectedRowStyle BackColor=”#D1DDF1″ Font-Bold=”True”

<HeaderStyle BackColor=”#e2eeff” Font-Bold=”True”
Font-Size=”Large” ForeColor=”White” />

<EditRowStyle BackColor=”#2461BF”/>

<AlternatingRowStyle CssClass=”ms-alternating”


The above code will result in a grid looking like below. I have used some SharePoint CSS (Core.css) to bring the SharePoint look.

The data should be displayed using bound columns. The SPDataSource can be used with SharePoint controls without any coding.

Given below is another example for binding data to InputFormCheckBoxList in SP.

<sharepoint:InputFormCheckBoxList ID=”InputFormCheckBoxList1″ runat=”server”
DataSourceID=”spdsSupervisor” DataTextField=”Title”/>

The above code will result in a checkbox list looking like the one below. On change of codes the assemblies need not be recompiled and deployed

To GAC. This means no building of WSP/CAB files and writing codes to copy assemblies to Global Assembly Cache. (Nice isn’t it)

Hassle free code with fewer bugs can be developed by using SPDataSource. There are different types of Datasourcemode-ListItem, CrossList, Webs, and ListOfLists.

SharePoint developers who develop applications and custom application pages with SharePoint as data store (Lists as tables) will be benefited by using SPDataSource.