Thursday, July 21, 2011

Creating an SPDataSource .NET control

To use an SP List as a data source for a .NET web control, declare an SPDataSource as shown:

<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Eq><FieldRef Name='Section'/><Value Type='Choice'>Get Started</Value></Eq></Where><OrderBy><FieldRef Name='SortOrder' Ascending='True' /></OrderBy></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/student-affairs/enrollment/" /> <asp:Parameter Name="ListName" DefaultValue="Transfer" /> </SelectParameters>
</SharePointWebControls:SPDataSource>


The SelectCommand property allows for filtering and sorting of results.

The ID for this data source will then go inot the DataSourceID field of the web control that uses the SP List, as shown below:

<asp:GridView ID="DataGrid1" runat="server" DataSourceID="spDataSource1">
...
</asp:GridView>

No comments:

Post a Comment