Tag Archives: InputFormCheckBoxList

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>”>
<SelectParameters>

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

</SelectParameters>
</SharePoint:SPDataSource>

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”/>

<Columns>

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

</asp:boundfield>

<asp:templatefield HeaderText=”Rating”
FooterStyle-HorizontalAlign=”Left”
HeaderStyle-Font-Bold=”true”
HeaderStyle-Font-Names=”verdana”
HeaderStyle-ForeColor=”#525252″
ItemStyle-HorizontalAlign=”Right”>

<ItemTemplate>

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

        <asp:ListItem>1</asp:ListItem>

        <asp:ListItem>2</asp:ListItem>

        <asp:ListItem>3</asp:ListItem>

        <asp:ListItem>4</asp:ListItem>

        <asp:ListItem>5</asp:ListItem>

        <asp:ListItem>N/A</asp:ListItem>

    </asp:RadioButtonList>

</ItemTemplate>

</asp:templatefield>

</Columns>

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

<SelectedRowStyle BackColor=”#D1DDF1″ Font-Bold=”True”
ForeColor=”#333333″/>

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

<EditRowStyle BackColor=”#2461BF”/>

<AlternatingRowStyle CssClass=”ms-alternating”
BackColor=”White”/>

</asp:GridView>

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”
CssClass=”ms-authoringcontrols”
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.

Advertisements