populate a dropdown listbox with C# - InfoPath Dev
in

InfoPath Dev

populate a dropdown listbox with C#

Last post 06-06-2006 10:42 PM by val3. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 05-26-2006 05:59 AM

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    populate a dropdown listbox with C#

    Hi!

    I want to populate a dropdown listbox from SQL with C#. This is my code so far:

    IXMLDOMNode nodeEmployees = thisXDocument.DOM.selectSingleNode("my:myFields/my:employees");
    //workersOnDepartment is a dropdown listbox

    Command.CommandText = "SELECT dbo.Employees.Name FROM dbo.Employees";
    SqlDataReader Reader5 = Command.ExecuteReader();

    while (Reader5.Read())
    {
    // HOW TO populate the nodeEmployees dropdown listbox //Reader5.GetValue(0).ToString() is contains employee name
    }
    Reader5.Close();

    Thanks for any help in advance.
  • 05-26-2006 01:34 PM In reply to

    Re: populate a dropdown listbox with C#

    Hi,
    Welcome to the Forum!
    You cannot get reference to the Node that is bound to a dropdown and set the values for the dropdown. You either need to fill in a secondary datasource file with the that you have and bind that secodnary datasource node to the dropdown in the Infopath design.

  • 05-28-2006 02:07 AM In reply to

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    Re: populate a dropdown listbox with C#

    quote:
    Originally posted by Agni Jonnalagadda

    Hi,
    Welcome to the Forum!
    You cannot get reference to the Node that is bound to a dropdown and set the values for the dropdown. You either need to fill in a secondary datasource file with the that you have and bind that secodnary datasource node to the dropdown in the Infopath design.





    Thanks. How can I do that? :) I have to create some kond of dummy secoundary data source, than change the bind to a real one in code?
  • 05-28-2006 09:28 PM In reply to

    Re: populate a dropdown listbox with C#

    Yes. You will prepare a dummy xml file how your secondary datasource will look like and dump the data dynamically into the secondary datasource from the code.
  • 05-29-2006 12:45 PM In reply to

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    Re: populate a dropdown listbox with C#

    Can you specify in more detail what should I do? Can you give me a codesnippet?

    Thanks for your precious time helping me in advance,
    B.
  • 05-29-2006 02:34 PM In reply to

    Re: populate a dropdown listbox with C#

    Val3,

    Please check out these HowTos:http://infopathdev.com/howto/tutorials/default.aspx?i=987250af134b4ced85cbddc7db724202
    http://infopathdev.com/howto/tutorials/default.aspx?i=7f693c75c5c94604b01bdfd3a1edaedc

    Agni is talking about setting up the drop-down to populate from a 2DS as described in the second HowTo, and then to edit the entries in the drop-down add and remove nodes to the 2DS with code. Do it this way, however, will need to be done every time the form is opened as changes to the 2DS are not saved with the template./
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-02-2006 05:10 AM In reply to

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    Re: populate a dropdown listbox with C#

    Thanks Matt for the how-to link, thay are really interesting. My only problem is that I want to use managed code (C#). I was able to build the form described in the 2nd how to, but I don't know how to set the selected item:
    "You will need to use the sSelectedValue parameter to identify which of the option elements is the currently selected option. You must make sure that, in your code, you set the selected="selected" attribute on the correct option element. Otherwise the drop-down list in the view will never show the selected value, but will instead always revert back to displaying the first option in the list."
    How can I do that?

    Thanks again in advance,
    B.
  • 06-02-2006 05:43 AM In reply to

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    Re: populate a dropdown listbox with C#

    ok, I have a callback every time I select an item form the dropdown listobx, but the sSelectedValue is always empty. Why?
  • 06-06-2006 10:42 PM In reply to

    • val3
    • Not Ranked
    • Joined on 05-25-2006
    • Posts 6

    Re: populate a dropdown listbox with C#

    Dear Matt or someone else,

    please reply to my last post.

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