Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Suvarna 10 posts 30 karma points
    Nov 09, 2009 @ 09:21
    Suvarna
    0

    dynamic populate of drop down with data from your inserted nodes

    Hi, I am new to umbraco, I want to create dropdown list which contains name of the node which i created in content tree. My problem is i have some categories which i want to show in dropdownlist. I will create a node for each categories. under each category node i will have subnodes which will have propety called question. When i select a category in drop down it should display all questions . Is it possible to do this. if possible please focus light on this. Earlier reply will be appreciated.

    Thanks in advance

    Suvarna

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2009 @ 09:35
    Dirk De Grave
    0

    Suvarna,

    Can be done quite easily using xslt (and macro)

    <xsl:variable name="startNode" select="-1" />
    <select>
    <option value="">--Select category--</option>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($startNode)//node [@nodeTypeAlias = 'Category']">
    <option value="{@id}"><xsl:value-of select="@nodeName"></option>
    </select>

    will create a dropdown list of categories from the nodes (starting from a $startNode - set to -1 here = top level node). All that needs to be done now is display all questions upon selectnig a category from the dropdown.

     

    Hope this helps.

    Regards,

    /Dirk

     

     

     

  • Suvarna 10 posts 30 karma points
    Nov 09, 2009 @ 10:38
    Suvarna
    0

    Hi Dirk, thanks for the quick reply. I alredy did the same thing for populating dropdown but how can i handle postback for this i mean once i select a category how will i show the questions of that category. In the content tree there will be many content node which will have a property called question for each category.

    Thanks,

    Suvarna

  • Jannik Nilsson 38 posts 81 karma points
    Nov 09, 2009 @ 10:50
    Jannik Nilsson
    0

    If you're going to use xslt then your best bet would be to post back via javascript. Something like this: document.formName.submit()

     

  • Suvarna 10 posts 30 karma points
    Nov 09, 2009 @ 10:56
    Suvarna
    0

    Hi jannik, I am not clear about this point. can you please elaborate this point in more deep?

    Thanks,

    Suvarna

  • Suvarna 10 posts 30 karma points
    Nov 09, 2009 @ 11:08
    Suvarna
    0

    You can see this link the way i want to do for dropdown control

    http://www.atagverwarming.nl/default.aspx?cp=faq

  • Jannik Nilsson 38 posts 81 karma points
    Nov 09, 2009 @ 11:15
    Jannik Nilsson
    0

    If I'm reading your question correctly you have a page with a dropdown box on it with some questions in it. When you select a question the answers should be shown.

    Now there are a few way you can show the answers, either redirect to a page with the relevant answers when you select a question.

    In the value attribute of the different options add the url to the answers page, and then just redirect to that page.

    Another way is to submit to the same page with a query parameter containing the id of the question asked and then show the children of that node with xslt

  • dandrayne 1138 posts 2262 karma points
    Nov 09, 2009 @ 11:19
  • Jannik Nilsson 38 posts 81 karma points
    Nov 09, 2009 @ 11:42
    Jannik Nilsson
    0

    Try somethig like this, it's not tested so errors might occur :)

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib ">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>
        <xsl:variable name="category" select="umbraco.library:Request('ctrlCategory')" />
        <xsl:variable name="question" select="umbraco.library:Request('ctrlQuestion')" />

        <xsl:template match="/">
            <form name="myForm" action="{umbraco.library:NiceUrl($currentPage/@id)}" method="post">
                <div>
                    <xsl:variable name="startNode" select="-1" />
                    <select name="ctrlCategory" onchange="document.myForm.submit()">
                        <option value="">--Select category--</option>
                        <xsl:for-each select="umbraco.library:GetXmlNodeById($startNode)//node [@nodeTypeAlias = 'Category']">
                            <option value="{@id}">
                                <xsl:if test="$category = @id">
                                    <xsl:attribute name="selected">
                                        <xsl:text>selected</xsl:text>
                                    </xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="@nodeName" />
                            </option>
                        </xsl:for-each>
                    </select>
                </div>
                <xsl:if test="$category != ''">
                    <div>
                        <xsl:call-template name="categoryTemplate">
                            <xsl:with-param name="category" select="$category" />
                        </xsl:call-template>

                        <xsl:if test="$question != ''">
                            <xsl:call-template name="questionTemplate">
                                <xsl:with-param name="question" select="$question" />
                            </xsl:call-template>
                        </xsl:if>
                    </div>
                </xsl:if>
            </form>
        </xsl:template>

        <xsl:template name="categoryTemplate">
            <xsl:param name="category" />
            <!-- Output the questions for the category -->
            <xsl:for-each select="umbraco.library:GetXmlNodeById($category)">
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>
                        <xsl:text>?ctrlCategory=</xsl:text>
                        <xsl:value-of select="$category"/>
                        <xsl:text>&amp;question=</xsl:text>
                        <xsl:value-of select="@id"/>
                    </xsl:attribute>
                    <xsl:value-of select="./@name"/>
                </a>
            </xsl:for-each>
        </xsl:template>

        <xsl:template name="questionTemplate">
            <xsl:param name="question" />
            <!-- Output the answers for the selected question -->
            <xsl:value-of select="umbraco.library:GetXmlNodeById($question)/data [@alias='file']" />
        </xsl:template>
    </xsl:stylesheet>
  • Suvarna 10 posts 30 karma points
    Nov 10, 2009 @ 06:14
    Suvarna
    0

    Hi Jannik, the solution you gave is really corrrect way of implementation and its working. but i already have one master page in which i took the form tag. and my funcionality in in content page in which i can not take the form tag. can you suggest some solution for this?

    Thanks,

    Suvarna

     

  • Jannik Nilsson 38 posts 81 karma points
    Nov 10, 2009 @ 09:16
    Jannik Nilsson
    0

    just use: document.forms[0].submit()

  • Touhid 97 posts 117 karma points
    Nov 08, 2010 @ 12:24
    Touhid
    0

    Hi,

    Im confused about @id.can you help me?

    touhid

Please Sign in or register to post replies

Write your reply to:

Draft