InfoPath designer repeating table example

This InfoPath tutorial explains we will discuss InfoPath designer repeating table example, Show SharePoint list data in repeating table in InfoPath, Add auto number to repeating table rows in InfoPath, Show SharePoint list data in repeating table in InfoPath 2010 using SharePoint object model, Delete all rows of a repeating table in InfoPath 2010 programmatically.

Show SharePoint list data in repeating table in InfoPath

This InfoPath 2010 tutorial explains how to show a SharePoint list data in a repeating table in InfoPath 2010 in SharePoint 2010.

In the same way, we can display SharePoint 2010/2013 list data using a repeating table in InfoPath 2010/2013.

Till now I am assuming, you have a SharePoint list and a data connection that will retrieve the data from the SharePoint 2010 list. In this example I have a list name as “Employees” and my data connection name is Employees also.

You can create a blank InfoPath 2010 form. Now if you will check the data source, our main and new data source that we created in above should look like below:

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

Now expand the data fields of Employees data source and drag the d:SharePointListItem_RW to the blank InfoPath form, Once you drag and drop, it will ask you 3 things:

  • Repeating Table
  • Repeating Section with Controls
  • Repeating Section

Select the Repeating Table as shown in the figure below:

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

After you select the Repeating table, it will put the field, you can modify the column title in the Repeating table as well as you can delete any column if you do not want to show.

The below one is the default one which comes after I drag and drop.

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

The below one is the modified one which I modify in the repeating table:

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

After this, you can save and publish the form and once you open the form the data will be shown like below:

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

Remember all these fields are editable. If you want to make it read-only then right-click on a field in the repeating table and select Textbox properties and then go to the Display tab and select the Read-only checkbox as shown in the figure below.

 Show SharePoint list data in repeating table in infopath 2010

Show SharePoint list data in a repeating table in InfoPath 2010

Then click on Ok. Now the field will be in read-only mode.

This InfoPath 2010 SharePoint 2010 tutorial explains how to display SharePoint list data in a repeating table in InfoPath 2010/2013.

Add auto number to repeating table rows in InfoPath 2010/2013 in SharePoint

This InfoPath 2010 tutorial explains, how to add an auto number to repeating table rows in InfoPath 2010 in SharePoint 2010. It is like adding a serial number field into the repeating table rows in the InfoPath form.

For this add a repeating table to the InfoPath form. By default, the fields will come as the textbox field. So change the particular fields on which you want the auto number to come. Right click on the field -> Change Control -> Calculated value as shown the figure below:

add auto number in infopath form
Add an auto number to repeating table rows in InfoPath 2013 or InfoPath 2010 in SharePoint

Then double-click on the field and from the ribbon click on Default value from the Properties tab as shown in the figure below:

Add auto number to repeating table rows in infopath 2013 or InfoPath 2010 in SharePoint
Add an auto number to repeating table rows in InfoPath 2013 or InfoPath 2010 in SharePoint

The above step will open the Field or Group Properties, from the Data tab click on the fx button on the Default value textbox as shown in the fig below:

how to add auto number in repeating table in infopath 2013
Add an auto number to repeating table rows in InfoPath 2013 or InfoPath 2010 in SharePoint

Then in the Insert Formula dialog box write the below formula and click on verify formula to check whether the formula contains an error or not. Remember to check Edit XPath (advanced) checkbox.

count(../preceding-sibling::*) + 1

The formula should look like below:

infopath 2013 auto number repeating table
Add an auto number to repeating table rows in InfoPath 2013 or InfoPath 2010 in SharePoint

Then click on Ok and also click on Ok in the Field or Group Properties dialog box. After you publish the form and you will see the auto number will come like 1,2,3,4,5…. serially for each row as shown in the fig below:

Add auto number to repeating table rows in infopath 2013 or InfoPath 2010 in SharePoint
Add an auto number to repeating table rows in InfoPath 2013 or InfoPath 2010 in SharePoint

Show list data in a repeating table in InfoPath 2010 using the SharePoint server object model

This InfoPath 2013 tutorial explains, how to show SharePoint 2010 list data in a repeating table using the SharePoint 2010 object model. We can use a repeating table in InfoPath 2010 to bind list date using the SharePoint object model

Here we will use the SharePoint object model to retrieve the data from a SharePoint 2010 list and bind to a repeating table in InfoPath 2010. Follow the below steps:

First Design a blank InfoPath form (Start -> All Programs -> Microsoft Office -> Microsoft InfoPath Designer 2010, then in the form Select Blank Form from the Popular Form Templates and click on Design Form).

Then in the form Put a Button and a Repeating table from the Controls tab. You can change the button control properties like ID and Text etc. Also, you can add the column names into the repeating table. So the form should like below:

Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model
Show SharePoint list data in repeating table in infopath 2010 using the SharePoint object model

Now we will change the fields in the repeating table by right click on the field and click on Text Box properties and then in the properties window, you can change the Field name. and also can make this to read-only. Do this for the 3 columns (3 textboxes). like below:

Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model
Show SharePoint list data in repeating table in infopath 2010 using the SharePoint object model

Once you rename the fields, the fields under the myFields should look like below:

Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model
Show SharePoint list data in repeating table in infopath 2010

Here we will do one more modification to the repeating table. By default in the repeating table, you can add new records to the InfoPath form. But here we only need to show the records in the InfoPath form. so to disable that, right click on the repeating table click on repeating table properties, there deselect the checkbox “Allow the user to insert and delete rows” as shown in the fig below. Then click on Ok.

Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model
Show SharePoint list data in repeating table in infopath 2010 using the SharePoint object model

Now the above steps finish our design of the InfoPath 2010 form. Now to write code follow the below steps:

Right click on the button, go to Button Properties… From the Properties window click on Edit Form Code button… This will open the visual studio where we will write the code.

Here we will use the SharePoint object model. So first add a reference to the MicroSoft.SharePoint.dll by going to the References folder and right click and click add references. The dll will be available under .Net category.

Once added then write the using statement like below:

using Microsoft.SharePoint;

public void btnGetEmployees_Clicked(object sender, ClickedEventArgs e)
{
string myNamespace = NamespaceManager.LookupNamespace("my");

using (SPSite thisSite = new SPSite(ServerInfo.SharePointListUrl.ToString()))
{
using (SPWeb web = thisSite.OpenWeb())
{
SPList listEmployees = web.Lists["Employees"];
SPQuery objquery = new SPQuery();
SPListItemCollection items = listEmployees.GetItems(objquery);
if (items.Count > 0)
{
foreach (SPListItem item in items)
if (item != null)
{
using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group1", NamespaceManager).AppendChild())
{
writer.WriteStartElement("group2", myNamespace);
writer.WriteElementString("rptEmployeeID", myNamespace, item["Title"].ToString());
writer.WriteElementString("rptFirstName", myNamespace, item["fname"].ToString());
writer.WriteElementString("rptLastName", myNamespace, item["lname"].ToString());
writer.WriteEndElement();
writer.Close();
}
}
}
}
}
}

Point to remember here:

While coding for the WriteElementString you should follow the same order in which the fields are defined in the InfoPath form fields. For example, if you will change the order then it will not work.

writer.WriteElementString("rptFirstName", myNamespace, item["fname"].ToString());
writer.WriteElementString("rptEmployeeID", myNamespace, item["Title"].ToString());
writer.WriteElementString("rptLastName", myNamespace, item["lname"].ToString());

Now you can save the form and deploy the form. While deploying if you got this error “The form template cannot be published to the server. Sandboxed solutions are not enabled on the SharePoint server farm”.

Once successfully deployed the data should come like below:

Show SharePoint list data in repeating table in infopath 2010 using SharePoint object model
Show SharePoint list data in repeating table in infopath 2010 using the SharePoint object model

I hope this InfoPath 2010 SharePoint tutorial explains how to show SharePoint list data in the repeating table in InfoPath 2010 using the SharePoint object model.

Delete all rows of a repeating table in InfoPath 2010 programmatically in SharePoint 2010

This InfoPath 2010 tutorial explains how we can delete all rows of a repeating table in InfoPath 2010 programmatically in SharePoint 2010.

Below is the full code that will clear the repeating table data progrmmatically in InfoPath 2010 in SharePoint 2010:

XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNodeIterator tableRows = domNav.Select("/my:myFields/my:group1/my:group2", NamespaceManager);
if (tableRows.Count > 0)
{
for (int i = tableRows.Count; i > 0; i–)
{
XPathNavigator reTable = MainDataSource.CreateNavigator();
XPathNavigator reTableRows = reTable.SelectSingleNode("/my:myFields/my:group1/my:group2[" + i + "]", NamespaceManager);
reTableRows.DeleteSelf();
}
}

Below is the code that will delete the first row of the repeating table:

XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator singleRow = domNav.SelectSingleNode("/my:myFields/my:group1/my:group2[1]",NamespaceManager);
if (singleRow != null)
itemNav.DeleteSelf();

I hope this InfoPath 2010 tutorial explains, how to delete all rows of a repeating table in InfoPath 2010 programmatically in SharePoint 2010.

You may like following InfoPath tutorials:

We saw below InfoPath examples

  • Show SharePoint list data in repeating table in InfoPath
  • Add auto number to repeating table rows in InfoPath 2010/2013 in SharePoint
  • Show list data in a repeating table in InfoPath 2010 using the SharePoint server object model
  • Delete all rows of a repeating table in InfoPath 2010 programmatically in SharePoint 2010
Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>