Copied to clipboard

Flag this post as spam?

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


  • Desley 44 posts 169 karma points
    Mar 14, 2014 @ 15:33
    Desley
    0

    Displaying prevalues from selected checkbox

    Hey everyone,

    I have a checkbox with X amount of options and I want to print the prevalues of those that are selected on my page.

    If anyone could help me out it will be greatly appreciated!

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Mar 14, 2014 @ 15:55
    Peter Gregory
    1

    Hey Desley

    If you are using the standard Checkbox List datatype they will come back as a comma delimited list of values. eg hello,world

    You just need to take the value and split it on the comma.

    If you are using Umbraco MVC Views or partials.

    @{
         var yourVals = Model.Content.GetPropertyValue<string>("yourCheckBoxListVal").Split(',');
    }
    <ul>
    @foreach(var val in yourVals){
        <li>@val</li>
    }
    </ul>
    
  • Desley 44 posts 169 karma points
    Mar 14, 2014 @ 16:09
    Desley
    0

    Hi Peter,

    Your code works so it's a good step in the right direction. Although I am trying to print a bunch of content items on a overview page and if I try to add your code into the existing foreach it doesn't work.

    I have the following structure:

    @foreach (var item in dinnerItems)
                    {
                        <div id="dinnerItems">
                            <a href="@item.Url">@item.Name</a>
                            on
                            @String.Format("{0:dd-MM-yyyy}", item.EventDate)
                            at
                            @item.Country | @item.Address
    
                          //This is where I want to print the properties of the checkbox
    
                        </div>
                    }
    

    My apologies for not being quite clear enough.

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Mar 14, 2014 @ 16:20
    Peter Gregory
    100

    Ahhh! you are using Dynamics.

    Try this..

              @foreach (var item in dinnerItems)
                {
                    <div id="dinnerItems">
                        <a href="@item.Url">@item.Name</a>
                        on
                        @String.Format("{0:dd-MM-yyyy}", item.EventDate)
                        at
                        @item.Country | @item.Address
    
                      //This is where I want to print the properties of the checkbox
    
    
                     <ul>
                        @foreach(var val in item.CheckBoxProperty.Split(',')){
                           <li>@val</li>
                         } 
                     </ul>
    
    
                    </div>
                }
    
  • Desley 44 posts 169 karma points
    Mar 14, 2014 @ 16:27
    Desley
    0

    Perfect. Thank you!

  • Chad 65 posts 129 karma points c-trib
    Apr 01, 2014 @ 06:34
    Chad
    0

    Hi, so I'm trying to do the exact same thing, but my DataType is applied to a 'Member', not a regular content item. It seems that the referencing ID's are stored, not a text representation? I'm not sure how to get what the text should be for these values.

    Edit: Should point out, this is 7.1 RC

    Edit: Pretty sure this is actually a bug, have created a ticket here: http://issues.umbraco.org/issue/U4-4575

Please Sign in or register to post replies

Write your reply to:

Draft