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);
parent.AppendChild(row1);
}
row.DeleteSelf();
}
}
Your comments are most welcome.
No comments:
Post a Comment