Copied to clipboard

Flag this post as spam?

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


  • Robin Hansen 135 posts 368 karma points
    Oct 18, 2012 @ 13:39
    Robin Hansen
    0

    Display mediaFolderIds in a usercontrol

    I found this nice razorscript that looks in after a specific folder (1132 ) in the Media Libary and gives me the names and Ids of its Children... the script works as it's intended - however it's rather dirty and straight forward... - my point is that I need to do the very same in a usercontrol using a dynamic feed asp.net:DropDownList in order to get the SelecdedIndex... - I've NO clue hov to write something simular in a usercontrol

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;
    @using umbraco.cms.businesslogic.media;
    
    @{
        var folderId = 1132;
        var media = Model.MediaById(folderId);
        var folders = media.Children;
        <form method="post">
            <select id="folderId" name="folderId" onchange="window.location.href = 'http://@Request.Url.Host/galleri/' + this.form.folderId.options[this.form.folderId.selectedIndex].value">
            @foreach(var item in folders)
            {
                <option value="@item.Id">@item.Name</option>
            }
            </select>
        </form>
    }

    It does'ne nessecary need to redirect though - it's just a feature... :-)

  • Robin Hansen 135 posts 368 karma points
    Oct 23, 2012 @ 11:11
    Robin Hansen
    0

    ***Update***

    After a few (lots of) Googlesearches I finally succeded in creating above macroscript as a usercontrol... - the final resault looks as follows:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco.cms.businesslogic.media;

    public partial class usercontrols_galleryTeaser : System.Web.UI.UserControl
    {
    private int _pathTo;
    public int PathTo
    {
    get { return _pathTo; }
    set { _pathTo = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    int mediaId = PathTo;
    Media node = new Media(mediaId);
    var childrenNodes = node.Children;

    folderid.DataSource = childrenNodes;
    folderid.DataValueField = "Id";
    folderid.DataTextField = "Text";
    folderid.DataBind();
    }
    }

    protected void folderid_SelectedIndexChanged(object sender, EventArgs e)
    {
    Response.Redirect("/gallery/" + folderid.SelectedValue);
    }
    }

    Feel free to use anytime you whant... :-)

Please Sign in or register to post replies

Write your reply to:

Draft