Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Jun 05, 2014 @ 14:57
    Paul Griffiths
    0

    Binding specific content nodes to a dropdown

    Hello All,

    Using a c#' user control the following code Lists all child nodes of the current node and populates the dropdownlist with the values but how can I target a specific node of a specific doctype and display those values? It needs to be bullet proof so that it works from anywhere on the website as the search form is in the master template.

    public partial class UserControls_ExtendedSearch : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
    
                ddlLocation.DataSource = Node.GetCurrent().ChildrenAsList.Select(y =>
                {
                    return new
                    {
                        Name = y.Name,
                        Id = y.Id
                    };
                });
                ddlLocation.DataTextField = "Name";
                ddlLocation.DataValueField = "Id";
                ddlLocation.DataBind();
    
    
            }
        }
    
    }
    

    Thanks really stuck

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Jun 05, 2014 @ 15:19
    Paul Griffiths
    0

    This code will list all the numeric value of the nodes i want but not the string values. It also tells me a lot of the code is obsolete.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Sample 2. Get the current node with node factory and databind the properties as Anonymous Types.
            string docTypeAlias = "CityTown";
            DocumentType dt = DocumentType.GetByAlias(docTypeAlias);
            ddlLocation.DataSource = Document.GetDocumentsOfDocumentType(dt.Id);
            ddlLocation.DataTextField = "Id";
            ddlLocation.DataValueField = "Id";
            ddlLocation.DataBind();
    
    
        }
    }
    

    Thanks

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Aug 13, 2014 @ 13:48
    Paul Griffiths
    0

    Hi everyone im really struggling to get this to work and its the final thing holding me back.Im Looking if someone could possible point me in the right direction here please.

    To make it clear what im trying to achieve... I am wanting to build a cascading dropdownlist user control using c# and was wondering how the best way would be to target the specific nodes in my content tree in umbraco.

    For example if i had the following structure in my content section

    Merseyside   (type = county)
            Liverpool (type = city/town)
                 Area of Liverpool 1 (type = suburb)
                 Area of Liverpool 2 (type = suburb)
                 Area of Liverpool 3 (type = suburb)
            Birkenhead (type = city/town)
                 Area of Birkenhead 1 (type = suburb)
                 Area of Birkenhead 2 (type = suburb)
    etc......
    

    from the front end i am wanting to populate the first drop-down list with the city/towns (e.g Liverpool, Birkenhead) and based on the value that is selected by the user i want to automatically populate the second dropdownlist with the related child suburbs.

    How can I make the link between my user control and the umbraco content tree so I can target these nodes?

    Any help or advice would be greatly appreciated as I have tried using XSLT but unfortunately failed (http://our.umbraco.org/forum/developers/xslt/52622-Dependent-dropdown-list)

    Thanks all please could someone help? the code above demonstrates some of the code i have been messing with to get this to work.

    Thanks for reading

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft