Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 karma points
    May 03, 2013 @ 17:17
    Moran
    0

    getting values of checkbox data type

    Hi

    is there a way to get the value from a checkbox data type using razor? I mean the values and not the text of course.

    Thanks

  • Charles Afford 1163 posts 1709 karma points
    May 03, 2013 @ 19:39
    Charles Afford
    1

    You can do

    int preValue;

    Int32.TryParse(your property, out preValue);  //preValue as numeric value

    string preValueAsString = umbraco.library.GetPreValueAsString(preValue);

     

    Charlie :)

     

  • Moran 285 posts 934 karma points
    May 03, 2013 @ 20:12
    Moran
    0

    Great thanks is the syntax like this? instead of "your property"

    Model.dropdownList
  • Charles Afford 1163 posts 1709 karma points
    May 03, 2013 @ 20:24
    Charles Afford
    0

    that should be the one.  Are you using visual studio and are you using IIS?  If so you should be able to debug and see what value you are getting returned.  I think of the top of my head its @Model.GetProperty("dropdownList").Value.ToString().  It might be the object you need which would be @Model.GetProperty("dropdownList").Value.  Charlie :).  Please could you make this solved if this works :).  Thanks.  Charlie :) 

  • Moran 285 posts 934 karma points
    May 03, 2013 @ 20:44
    Moran
    0

    Thanks :)

    and another question please what if I want to get all the pre-values of this data type, like in my sceenshot getting all the numbers from 6 to 9 ?

  • Moran 285 posts 934 karma points
    May 03, 2013 @ 21:07
    Moran
    0

    Sorry but your answer didn't work for me, this code does:

     umbraco.cms.businesslogic.web.Document doc = new umbraco.cms.businesslogic.web.Document(Model.Id);
     @doc.getProperty("dropdownList").Value
  • Charles Afford 1163 posts 1709 karma points
    May 03, 2013 @ 21:18
    Charles Afford
    100

    It will do, all your code is diffrent is getting the xml version rather than a strongly typed access.

    ummm if you want to iterate through the values then i think you are going to need to parse the xml.  the easy way would be something like:

    XPathNodeIterator xpathIterator = umbraco.library.GetPreValues(preValue);

     string xmlStr = "";

                    foreach (XPathNavigator n in xpathIterator)

                    {

                        xmlStr = n.OuterXml;

                    }

                    var x = new XmlDocument();

                    x.LoadXml(xmlStr);

                    XmlNodeList nl = x.SelectNodes("//preValues/preValue");

                        foreach (XmlNode xn in nl)

                        {

                            var li = new ListItem(xn.InnerText, xn.Attributes["id"].Value);

    }

                  

  • Moran 285 posts 934 karma points
    May 03, 2013 @ 21:41
    Moran
    0

    Man you're great

    Thanks  a lot for your help, this is my code I used the Current property in order to loose the first foreach loop

    System.Xml.XPath.XPathNodeIterator iterate = umbraco.library.GetPreValues(-42);
    string xmlStr = iterate.Current.InnerXml;
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.LoadXml(xmlStr);
    System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes("//preValues/preValue");
    foreach (System.Xml.XmlNode item in xmlNodeList)
    {
    @item.Attributes["id"].Value
    }
  • Charles Afford 1163 posts 1709 karma points
    May 04, 2013 @ 09:45
    Charles Afford
    0

    Hi, glad you got it done :).  Can you maked this a solved :).  I see what you have done with XPathNodeIterator calling it iterate.  I dont know why but feels a bit obsure.

  • Moran 285 posts 934 karma points
    May 04, 2013 @ 13:18
    Moran
    0

    You're right, that a pretty poor naming convantion, but for this sample that'll do the trick :)

    Thanks

  • MikeD 92 posts 112 karma points
    Jun 18, 2013 @ 22:52
    MikeD
    0

    How do I get the actual text string?

  • MikeD 92 posts 112 karma points
    Mar 05, 2014 @ 18:10
    MikeD
    0

    I wonder if anyone is still paying attention to this thread...

    What I am trying to do is this.  I have a checkbox data type that is a list of job categories (jobsCategory).  

    The parent node (Find-A-Job) will have children for each job, and one of the fields on the doctype is of course the category.

    On the display page, I would like to iterate through all the categories, then under each one, show child nodes that have that value checked (if any).  Something like this:

    Construction

    Job 1

    Job 2

    Operations

    No Jobs found

    Service

    Job 1 

    Job 2

    Just in case anyone can help, and to avoid confusion, here are some ids:

    Parent Node (Find-A-Job): 1120

    datatypeId: 1127

    I know there has to be a way to do this, but I am not a programmer and am having a hard time trying to figure it out.  Any help would be most appreciated.

  • Moran 285 posts 934 karma points
    Mar 07, 2014 @ 06:31
    Moran
    0

    If you want the values you need something like this, when you use checkboxes you  get comma separated values.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    Layout = "Master.cshtml";
    }

    @{
    string imageStr = Model.Content.GetProperty("gallery").Value.ToString();
    IEnumerable<dynamic> images = imageStr.Split(new char[] { ',' });
    }
Please Sign in or register to post replies

Write your reply to:

Draft