Programmatically bind the textbox to Numeric data... - InfoPath Dev
in

InfoPath Dev

Programmatically bind the textbox to Numeric data...

Last post 01-09-2009 04:27 AM by jayant.sharma. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 01-08-2009 03:02 AM

    Programmatically bind the textbox to Numeric data...

    I have a text Box whose DataType is set to Whole Number. Now I want to set this textbox programmatically.

    The Problem is the SetValue() takes only the string argument. Is there any other method which return whole number or any other datatype. So that Programatically I can bind it the Controls of Different Data types.

     

    XPathNavigator root = MainDataSource.CreateNavigator();

    int i=10; //

    root.SelectSingleNode("/my:myFields/my:field6", NamespaceManager).SetValue("");

    // /my:myFields/my:field6 ----> This is Whole Number Data type.I have to set i=10 to it

     

    Please Help, Thanks in Advance

    Jayant Sharma

  • 01-08-2009 04:09 AM In reply to

    Re: Programmatically bind the textbox to Numeric data...

     

    Hi,

    Use the following code lines.

    XPathNavigator root = MainDataSource.CreateNavigator();

     

    object newValue = 10;

     XPathNavigator node = root.SelectSingleNode("/my:myFields/my:field11", NamespaceManager);

     

    if (node == null || newValue == null)

       return;

    string value = newValue.ToString();

     // The xsi:nil needs to be removed before we set the value.

     if ((node.NodeType != XPathNodeType.Attribute) && (value.Length != 0))

     {

         if ((node != null))

           {

               if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))

                    node.DeleteSelf();

           }

      }

    node.SetValue(value);

    Swathip
    www.ggktech.com
  • 01-08-2009 04:10 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Programmatically bind the textbox to Numeric data...

    Hi,

    Can you try below code.

    XPathNavigator root = MainDataSource.CreateNavigator();

                int i = 10; //
                XPathNavigator test = root.SelectSingleNode("/my:myFields/my:field6", this.NamespaceManager);

                test.SetValue(Convert.ToString(i));

     

    But you need to change the Textbox field as string. Otherwise you will get schema validation errors.

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 01-08-2009 08:36 PM In reply to

    Re: Programmatically bind the textbox to Numeric data...

    A Lot of Thanks... you have solved my big problem...

    Is there any condition when we have to reinsert the nillable back to the node. In which case we have to set the nillable attribute to true.

     

  • 01-08-2009 10:56 PM In reply to

    Re: Programmatically bind the textbox to Numeric data...

    Hi,

    Nillable attribute to true is set when the text box data type is numeric and the data in it is empty.

    Madhuri
    http://www.ggktech.com
  • 01-08-2009 10:58 PM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Programmatically bind the textbox to Numeric data...

    Hi,

    Do you want to set the nillable back on the button click or any other case?

    Can you give more details about this.

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 01-08-2009 11:23 PM In reply to

    Re: Programmatically bind the textbox to Numeric data...

    ya exactly, I want to set nillable back to the button. I want to know in which situation we have to set it back. means in which condion we have to set nillable false and true...

    Please see this link

    http://www.sharepointblogs.com/dooke/archive/2007/08/14/the-xsi-nil-attribute-the-correct-way.aspx

    and clerify me the condition in which we have to apply the nillable false

     

  • 01-09-2009 04:04 AM In reply to

    Re: Programmatically bind the textbox to Numeric data...

    Hi,

    When you want to set a value to node of type whole number, date, time, decimal and date and time then you have to set the nil value false. Use the following code lines to set nil to true to the node.

    if (node.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance") != null)

    {

     if ((node.Value).Length != 0)

     node.SetValue(String.Empty);

     

    if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))

     node.DeleteSelf();

                   

    // Create xsi:nil attribute with the proper namespace.

    node.CreateAttribute("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");

     }

    Swathip
    www.ggktech.com
  • 01-09-2009 04:27 AM In reply to

    Re: Programmatically bind the textbox to Numeric data...

    thanks

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