Thursday, July 3, 2008

How to fill values (Data) Repeating Table in InfoPath?

Hi All,
Here is sample code to fill value in repeating table at runtime (Dynamically)
Suppose you have repeating table Name “tblCustomer” and has two column name “Text” and “value”
Here is code to fill value from database or from web service.
Repeating table structure in data source like this

private void fillRepeatingTable(string table, string tr)
string value, Text;
value = string.Empty;
Text = string.Empty;
DataTable dt = null;
//this is method that Will return DataTable
dt = this.CustomerDataSource();
//cloumn name Value in Repeating Table
value = "//my:Value";
//column name Text in Repeating Table
Text = "//my:Text";

XPathNavigator root = this.MainDataSource.CreateNavigator();
XPathNavigator row = root.SelectSingleNode("//my:" + tr + "[1]", NamespaceManager);
// make a copy of the node by cloning it
XPathNavigator row1;
if (dt != null)
foreach (System.Data.DataRow dr in dt.Rows)
// set the new values of the row’s fields
row1 = row.Clone();
row1.SelectSingleNode(value, NamespaceManager).InnerXml =Convert.ToString(dr["Value"]);
row1.SelectSingleNode(Text, NamespaceManager).InnerXml = Convert.ToString(dr["Text"]).Replace("&", " "); ;
XPathNavigator parent = row1.SelectSingleNode("//my:" + table, NamespaceManager);

Your comments are most welcome.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to