Join MSSharePointTips!

subscribe to our feed
Follow us on LinkedIn
Follow us on Twitter
 
Special Offer: Enter Our Free SharePoint Book Giveaway


Multiple listing controls with a single datasource - InfoPath

Written By: Abin Jaik Antony -- 7/29/2010 -- join -- contribute -- (0) comments -- printer friendly version

Rating: Rate

Categories: InfoPath, MOSS 2007, WSS3
< Prev - 1 | 2 | - Next >

Problem

The scope of this article is to explain how to populate multiple InfoPath listing controls like a Drop-Down List and a List Box with only one datasource. The scenario can be like this:

Assume we have 2 to 3 SharePoint lists with data on our SharePoint site and we have some listing controls on our InfoPath form. The aim is to populate all these listing controls using only a single InfoPath datasource.

Solution

By default we do have four "Receive Data" options for InfoPath datasource like an XML document, DataBase,Web Service, and SharePoint Lists & Libraries. As mentioned in the "Problem", our aim is to populate data from different SharePoint lists to different listing controls on an InfoPath form. Usually, everyone will create different datasources from SharePoint lists for each listing control, but we can utilize the "Web service" option for populating many listing controls with a single datasource.

Prior to the development of this sample, we have to create 2 SharePoint lists inside a SharePoint Site. Name one SharePoint list "Names" and the other "Products". Fill these lists with some sample data. After populating these lists with data we can begin development.

First, we will create a webservice with a web method returning a dataset and deploy this to a SharePoint site. For SharePoint component development I use WSPBuilder to a large extent. You can download it from this location WSPBuilder. It’s a very easy and handy tool for the SharePoint development.

Follow the below steps to develop a webservice that's going to deploy to the SharePoint site.

  • Open the Visual Studio 2008/2005. Go to File Menu --> New-->Project -->WSPBuilder --> WSPBuilder Project. Name the Project as “SharePointDataServiceWSP”.
  • From the Solution Explorer, right click on the Project and choose the “Add new item” option. From the window, select the option “WebService” under the WSPBuilder category and name the webservice “GetData”.
  • Switch to the code behind the "GetData.asmx" webservice file, which we can see under the "WebServiceCode" folder of the WSP Project.
  • Add the below WebMethod (GetDataSet) to the code behind.
  • [WebMethod]
    public DataSet GetDataSet()
    {
    //Creation of the Dataset
    DataSet ds = new DataSet();
    ds.DataSetName = "ParentDS";
    
    //Creation Datatables for Names and Products
    DataTable dtNames = new DataTable();
    DataTable dtProducts = new DataTable();
    
    SPSite site = new SPSite("http://servername:port/");
    SPWeb web = site.OpenWeb();
    SPQuery namesQuery = new SPQuery();
    namesQuery.Query = "";
    SPList listNames = web.Lists["Names"];
    SPListItemCollection itemNamesCollections = 
    listNames.GetItems(namesQuery); //assigning SharePoint list item collections to the datatable - Names dtNames = itemNamesCollections.GetDataTable(); SPQuery queryProducts = new SPQuery(); queryProducts.Query = ""; SPList listProducts = web.Lists["Products"]; SPListItemCollection itemProductCollections =
    listProducts.GetItems(queryProducts); //assigning SharePoint list item collections to the datatable - Products dtProducts = itemProductCollections.GetDataTable(); //Adding datatables to the DataSet ds.Tables.Add(dtNames); ds.Tables.Add(dtProducts); //returning DataSet return ds; }
  • Build the code.
  • Build the WSP and Deploy the WSP to your site
  • After the deployment we can see the webservice under the _layouts folder of the SharePoint site. It will be like this:

    http://servername:port/_layouts/GetData.asmx

< Prev - 1 | 2 | - Next >



Sponsor Information


Valuable SharePoint resources all for free – Check it out

SQL Server Problems? Find real world solutions for free! Join the mssqltips community

CaeerQandA.com Shed some light on your future


Copyright (c) 2010 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


CareerQandA.com | MSSharePointTips.com | MSSQLTips.com