Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 05, 2013 @ 13:17
    Ismail Mayat
    0

    Datatype grid access data

    Guys,

    I am using uComponents 5.4.1.0 in Umbraco 6.1.1. I have created datatype grid it has 2 properties number and textstring. Have added property to my doc type called answers. My razor code looks like

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using Common.Model

    @using System.Xml.Linq

     

    @helper RenderQuestions(dynamic questionsNode){

     

       

              @foreach (var question in questionsNode.Children)

              {

       

       

    •  

                      @question.GetPropertyValue(DocumentType.Questions.Question.QuestionText)

       

       

                      @{

                          dynamic answers = question.GetPropertyValue(DocumentType.Questions.Question.Answers);

                          @answers.ToXml()

                      }

       

    •  

       

              }   

       

     

    }

     

     

    @{

        var questionsNode = uQuery.GetNodesByType(DocumentType.Questions.Alias).FirstOrDefault();

        dynamic qNode = Model.NodeById(questionsNode.Id);

     

        @RenderQuestions(qNode)

     

        /*

        if (!string.IsNullOrEmpty(Request.QueryString["recordid"]))

        {

            @RenderQuestions()

        }

        else

        {

            //they have navigated here without filling in data capture form

            Response.Redirect("/",true);

        }*/

    }

    Its erroring on .ToXml() ) string' does not contain a definition for 'ToXml'  

    Am i missing something?

    Regards

    Ismail

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 05, 2013 @ 13:24
    Dave Woestenborghs
    0

    Have you tried @question.answers.ToXml()

    Haven't tested it, just looking at the code samples here : http://ucomponents.org/data-types/datatype-grid/razor-samples/

     

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 05, 2013 @ 13:36
    Dave Woestenborghs
    0

    I just looked in a old project and I used this code with datatype grid before

     

    XDocument doc = XDocument.Parse(propertyvalue);
    
    var items = doc.Descendants("item");
    
    foreach (XElement item in items)
    {
    item.Element("prop1").Value;
    item.Element("prop2").Value;
    }
    

     

    That seems to work.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 05, 2013 @ 13:38
    Ismail Mayat
    100

    Ok just sorted,

     var answerXml = Library.ToDynamicXml(question.GetPropertyValue(DocumentType.Questions.Question.Answers));

                        foreach (var answer in answerXml)

                        {

                                @answer.answer.InnerText

                        }

    works as well

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 05, 2013 @ 13:42
    Dave Woestenborghs
    0

    Nice..that's even cleaner

Please Sign in or register to post replies

Write your reply to:

Draft