Get current value of row fields in a repeating table - InfoPath Dev
in

InfoPath Dev

Get current value of row fields in a repeating table

Last post 04-11-2008 01:23 PM by Chris Wasser. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-11-2008 01:10 PM

    Get current value of row fields in a repeating table

    I have built a browser compatible InfoPath 2007 form which has a repeating table to add items.  After the user types in an item, I have an after changed event handler that looks up the item number in a database and returns a value.  This part all works fine as long as I am on the first row of the repeating table.  When I add a new row to the table and attempt the same process, my XPath values are always referencing the first row in the repeating table rather than the current row.  I have modelled my code after this article from Microsoft (http://msdn2.microsoft.com/en-us/library/bb509311.aspx) and cannot for the life of me figure out how to get the context of the current row.  Any thoughts/ideas/solutions would be greatly appreciated. 

    -Chris 

    C# code follows:

    public void PartNumber_Changed(object sender, XmlEventArgs e)

    {

    try

    {

    // Check if value has changed and not a table insertion

    if (e.Operation == XmlOperation.ValueChange)

    {

    string connString = ("Data Source=x;User Id=y;Password=y;Initial Catalog=a;");

    string desc = null;

    string sql = null;

    SqlDataReader reader = null;

    // Get Current Row

    XPathNavigator xNavigator = e.Site.CreateNavigator();

    xNavigator.MoveToParent();

    // Get Reference to the part number

    string item = xNavigator.SelectSingleNode("/my:myFields/my:Parts/my:Part/my:PartNumber", this.NamespaceManager).InnerXml;

    using (SqlConnection conn = new SqlConnection(connString))

    {

    conn.Open();

    sql =
    "SELECT field1 FROM Table1 WHERE Field2 = " + item;

    // 1. create a command object identifying the query

    SqlCommand cmd = new SqlCommand(sql, conn);

    // 2. set the command object so it knows to execute a query

    cmd.CommandType = CommandType.Text;

    reader = cmd.ExecuteReader();

    while (reader.Read())

    {

    //Set its value to whatever it needs to be

    desc = reader["itemdesc"].ToString();

    xNavigator.SelectSingleNode("/my:myFields/my:Parts/my:Part/my:PartDescription", this.NamespaceManager).SetValue(desc);

    }

    }

    }

    }

  • 04-11-2008 01:23 PM In reply to

    Re: Get current value of row fields in a repeating table

    ok so, right after posting this message I figured it out.

    changed:

    string item = xNavigator.SelectSingleNode("/my:myFields/my:Parts/my:Part/my:PartNumber", this.NamespaceManager).InnerXml;

    to

    string item = xNavigator.SelectSingleNode("my:PartNumber", this.NamespaceManager).InnerXml;

    and

    xNavigator.SelectSingleNode("/my:myFields/my:Parts/my:Part/my:PartDescription", this.NamespaceManager).SetValue(desc);

    to

    xNavigator.SelectSingleNode("my:PartDescription", this.NamespaceManager).SetValue(desc);

     All is good.

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.