Using WBQuery to create a DataTable to bind to an SPGridView

We are going to re-use the query from the page Searching for work boxes owned by a particular team in order to show how the results of such a query can be bound to an SPGridView. Here we're not going to look at how the ASPX page looks like that holds the SPGridView, we're just going to assume it exists with the name SelectedWorkBoxes

WBTaxonomy teams = WBTaxonomy.GetTeams(SPContext.Current.Site);
WBTeam financeTeam = teams.GetSelectedTeam(“Islington Council/Finance”);

using (WBCollection collection = new WBCollection("http://collection/foi"))
    WBQuery query = new WBQuery();
    query.AddEqualsFilter(WBColumn.OwningTeam, financeTeam);

    // Add the view columns that we are interested to retrieve for the DataTable:

    // Now define how the DataTable columns should be viewed in the SPGridView:
    SelectedWorkBoxes.Columns.Add(WBUtils.BoundField(WBColumn.Title, HorizontalAlign.Center, null, true));
    SelectedWorkBoxes.Columns.Add(WBUtils.BoundField(WBColumn.WorkBoxURL, HorizontalAlign.Center, null, true));
    SelectedWorkBoxes.Columns.Add(WBUtils.BoundField(WBColumn.WorkBoxStatus, HorizontalAlign.Center, null, true));

    // This is the method on the WBC that creates the DataTable using the query:
    DataTable dataTable = collection.Query(query);

    // And then bind the DataTable to the SPGridView:
    SelectedWorkBoxes.DataSource = dataTable;


Last edited May 8, 2014 at 12:26 AM by OliSharpe, version 9


No comments yet.