Drop Down List with Repeating control and C# - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Drop Down List with Repeating control and C#

Last post 02-12-2013 09:02 AM by SeanPRyan. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 02-08-2013 01:12 PM

    • SeanPRyan
    • Top 500 Contributor
      Male
    • Joined on 02-02-2012
    • Kansas City area
    • Posts 45

    Drop Down List with Repeating control and C#

    I found some code to help me fill a drop down list that is listed here.   It works fine.  However, I need the drop down list to display a friendly choice while the back-end should pass a number value.  I don't know where to enter this.  Can anybody help by looking at this code?  I fill a repeating control and then I use that to fill the drop down.

      conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    DataSet ds = new DataSet();
                    da.Fill(ds);

                    XPathNavigator Loc = nav.SelectSingleNode("/my:myFields/my:Fddl", this.NamespaceManager);
                    Loc.SetValue("");

                    XPathNavigator tempNode = Loc.Clone();
                

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        XPathNavigator newNode = tempNode.Clone();
                        string value = dr[0].ToString();
                        string nm = dr[1].ToString();
                        newNode.SetValue(nm);                   
                        Loc.InsertAfter(newNode);
                    }

    Sean
    Filed under: , , ,
  • 02-09-2013 04:56 PM In reply to

    Re: Drop Down List with Repeating control and C#

    Hi SeanPRyan,

    You can manually change the XSL file for your view to display the "friendly value". To get at the XSL, just go to File>Publish>Export Source Files. Open up the view and search for the dropdown. The XSL file will accept xpath and you can customize what it shows in the dropdown. This should roundtrip when you use the InfoPath Designer but if not, you can use an xd:Preserve block around it. Lots of stuff to learn but this is definitely possible. Please search for "customize dropdown in XSL" and if you don't find anything, send me an email and I'll send you a sample.

    Best,

    P

    Patrick Halstead
    Project Manager at Qdabra
  • 02-11-2013 06:15 AM In reply to

    • SeanPRyan
    • Top 500 Contributor
      Male
    • Joined on 02-02-2012
    • Kansas City area
    • Posts 45

    Re: Drop Down List with Repeating control and C#

     Excellent!  I will give this a go and let you know how it works out.  Thanks very much for the response.

    Sean
  • 02-11-2013 01:48 PM In reply to

    • SeanPRyan
    • Top 500 Contributor
      Male
    • Joined on 02-02-2012
    • Kansas City area
    • Posts 45

    Re: Drop Down List with Repeating control and C#

     Here's what I have in the view1.xsl file.  I am not sure where to edit.  My guess is <xsl:if test="not(my:Fddl[.=$val] or $val='')">

     

    <select style="WIDTH: 310px" class="xdComboBox xdBehavior_Select" title="" size="1" xd:xctname="dropdown" xd:CtrlId="CTRL138" xd:binding="my:PM" xd:boundProp="value" value="" tabIndex="0">
                                                    <xsl:attribute name="value">
                                                        <xsl:value-of select="my:PM"/>
                                                    </xsl:attribute>
                                                    <xsl:choose>
                                                        <xsl:when test="function-available('xdXDocument:GetDOM')">
                                                            <option/>
                                                            <xsl:variable name="val" select="my:PM"/>
                                                            <xsl:if test="not(my:Fddl[.=$val] or $val='')">
                                                                <option selected="selected">
                                                                    <xsl:attribute name="value">
                                                                        <xsl:value-of select="$val"/>
                                                                    </xsl:attribute>
                                                                    <xsl:value-of select="$val"/>
                                                                </option>
                                                            </xsl:if>
                                                            <xsl:for-each select="my:Fddl">
                                                                <option>
                                                                    <xsl:attribute name="value">
                                                                        <xsl:value-of select="."/>
                                                                    </xsl:attribute>
                                                                    <xsl:if test="$val=.">
                                                                        <xsl:attribute name="selected">selected</xsl:attribute>
                                                                    </xsl:if>
                                                                    <xsl:value-of select="."/>
                                                                </option>
                                                            </xsl:for-each>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <option>
                                                                <xsl:value-of select="my:PM"/>
                                                            </option>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </select>

    Sean
  • 02-11-2013 02:26 PM In reply to

    Re: Drop Down List with Repeating control and C#

    Couldn't you just change your secondary data source to have one node for the value and another for the display? And just populate when the code runs? At any rate, I think you should be able to change the XPath here:

    </xsl:if>
    <xsl:value-of select="."/>
    </option>

    To your formula for your desired display.

    Hilary Stoupa

  • 02-11-2013 02:28 PM In reply to

    • SeanPRyan
    • Top 500 Contributor
      Male
    • Joined on 02-02-2012
    • Kansas City area
    • Posts 45

    Re: Drop Down List with Repeating control and C#

     Thanks for the reply Hilary.  I actually had that at first and it was failing for me; error on my part I'm sure :-)  I will keep working on it.

    Sean
  • 02-11-2013 02:33 PM In reply to

    Re: Drop Down List with Repeating control and C#

    Do you know how to run your code in debug? It can really help you figure out why something isn't working if you are writing custom code.
    Hilary Stoupa

  • 02-12-2013 09:02 AM In reply to

    • SeanPRyan
    • Top 500 Contributor
      Male
    • Joined on 02-02-2012
    • Kansas City area
    • Posts 45

    Re: Drop Down List with Repeating control and C#

    Hilary; yes.  I run in debug quite a bit.  I am divided among projects and can't dedicate myself to a single one at any given time.  I am still learning the ins and outs of InfoPath and XPath in particular.  This site is great and I always return to these to get my code working again. Thanks for the help. I will get this working when I have a half hour to spare :-)

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