Copied to clipboard

Flag this post as spam?

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


  • Neil Norpa 24 posts 44 karma points
    Dec 05, 2011 @ 12:41
    Neil Norpa
    0

    Razor populate Drop down list with document type filter property

    Hi,,

     

    I have created a document type resturant  which has a filter property called type which lists all the resturants but, i need to filter the resturants by type a property set with in the content within the docType property  type, i need to firstly populate the DDL with all the types excluding any duplication and then filter the nodes according to the filter

     

    Please coulsd you give me any pointers as to how to do the first part , as am sure the latter will

    be just passing the value into the razor foreach listing code i have see below.

               <div class="article">
                    @foreach (var resturant in itemGroup)
                    {
                        var newsCopy = resturant.BodyText;
                        newsCopy = Library.StripHtml(newsCopy);
                        newsCopy = Library.Truncate(newsCopy, 500, true);
                
                        <article class="item">
                             <h3>@resturant.Name</h3>
                              <p>@newsCopy</p>
                        </article>           
                    }
                </div>

     

     

    regards

     

    Neil.

     

  • Stephen 204 posts 246 karma points
    Dec 05, 2011 @ 12:49
    Stephen
    0

    Hey Neil,

    I had to do this last week so I used a control which (using nodefactory) which creating a DDL displaying all the current services availbale on the clients site for a feedback form. You can see this here on my test server.

    http://development.glasgowplastering.co.uk/get-quote.aspx

    I used a control because I was developing the feedback form anyway...there may well be an easier way to do this without the need for a control.

    Regards,

    Stephen

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 05, 2011 @ 13:21
    Sebastiaan Janssen
    0

    It should be as simple as adding a Where clause to your foreach, for example:

     @{ var type = Request["type"]; }
    @foreach (var resturant in itemGroup.Where("type == " type) {
    // do your thing

     

  • Neil Norpa 24 posts 44 karma points
    Dec 05, 2011 @ 17:19
    Neil Norpa
    0

    I know this is probably a simplw answer but how do i populate the ddl with the dta type i have created which is control render of Dropdown list.

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 05, 2011 @ 17:25
    Sebastiaan Janssen
    0

    Do you have some example code? I don't know what you're trying to ask here.. sorry.

  • Stephen 204 posts 246 karma points
    Dec 05, 2011 @ 17:28
    Stephen
    0

    I'm pretty sure this is what your trying to do...http://our.umbraco.org/wiki/reference/code-snippets/databind-node-children? except on a drop down list.

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 05, 2011 @ 17:35
    Sebastiaan Janssen
    0

    @Stephen can't mix user controls and Razor scripts though. What are you using Neil? I was assuming Razor as this IS the Razor forum.. 

  • Neil Norpa 24 posts 44 karma points
    Dec 08, 2011 @ 15:29
    Neil Norpa
    0

    he is my code

    @{
        var pagesToList = @Model.Children.Where("Visible");

        //Check macro param is not empty, if so default to 6 otherwise use the Parameter value
        var itemsPerPage = String.IsNullOrEmpty(Parameter.noPerPage) ? 2 : int.Parse(Parameter.noPerPage);
      
        //Count number of items from pagesToList variable
        var numberOfItems = pagesToList.Count();
        
        //Set the currentPage to 1
        int currentPage = 1;

        /*
            If we cannot parse a number from requesting the querystring param 'page' then set to 1,
            otherwise set the querystring value to our currentPage variable
        */
        if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage))
        {
            //No querystring found or not a number, so set currentPage to 1
            currentPage = 1;
        }
        
        //Subtract one from the currentPage variable (to use a zero based index, first page = 0)
        currentPage--;

        //Number of Pages (Maths time!)
        /*
            Divide the numberOfItems by itemsPerPage and then round the number up to
            next whole number and add one to the result (eg: 5.1 = 6 + 1 = 7)
        */
        var numberOfPages = Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) + 1;
        //var outlettype = HttpContext.Current.Request.QueryString["type"]
        
        //Display the items in groups of 3 wrapped with a <div>
        <div id="gridText">
            @*
                For each Repeater from our source (pagesToList)
                Where the page querystring = 2 /currentPage = 1...
                Skip over 6 records (currentPage * itemsPerPage) eg: 1*6 = 6
                Take 6 records, which grabs 7,8,9,10,11 & 12
            *@
             @*
              /* @foreach (var Repeater in itemGroup
                              .Where("@repeater.type == " outlettype  ) */
      *@
            @foreach (var itemGroup in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage) .InGroupsOf(3))
            {
               <div class="list">

             
                    @foreach (var Repeater in itemGroup )
                    {
                        var newsCopy = Repeater.BodyText;
                        newsCopy = Library.StripHtml(newsCopy);
                        newsCopy = Library.Truncate(newsCopy, 500, true);
                
                        <div class="article">
                             <h3>@Repeater.Name</h3>
                              <p>@newsCopy</p>
                        </div>           
                    }
                </div>
            }
        </div>
        
        
        <ul class="paging">
        @{
            /*
                pageQuerystring = 1 == 0 = currentPage
                pageQuerystring = 2 == 1 = currentPage
            */        
            
            //PREVIOUS Link
            <li>
                @if (currentPage > 0)
                {
                    <a href="?page=@(currentPage)">&laquo; Previous</a>
                }
                else
                {
                    <span class="disabled_paging">&laquo; Previous</span>
                }
            </li>

            
            //Create a variable 'pages' that stores from 1 to the numberOfPages variable
            var pages = Enumerable.Range(1, (int)numberOfPages);
            
            //Loop through the numbers in the Pages variable
            foreach (var number in pages)
            {
                <li>
                    @if (number - 1 != currentPage)
                    {
                        <a href="?page=@number">@number</a>
                    }
                    else
                    {
                        <span class="active_link">@number</span>
                    }
                </li>
            }

            //NEXT Link
            <li>
                @if (currentPage < pages.Count() - 1)
                {
                    <a href="?page=@(currentPage + 2)">Next &raquo;</a>
                }
                else
                {
                    <span class="disabled_paging">Next &raquo;</span>
                }
            </li>
        }
        </ul>
    }

    This lists, pages and truncates my content but i have created to other propertie within the document type called location and type which i want to use to refine the results, the question i have it how do i add pass the refined properties from a DDL which ill need to populate based on the doc type to the script and refine using the where.

    Also do i need a usercontrol for the DDL? of do i need to create a data type populated manuallyand render it in the template then on click pass results to the script.

    Roll on christmas...

     

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies