Copied to clipboard

Flag this post as spam?

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


  • Anton Oosthuizen 206 posts 486 karma points
    Nov 15, 2012 @ 10:19
    Anton Oosthuizen
    0

    uComponents DatatypeGrid - Add data via user control

    Hi

    How will I go about adding data to DatatypeGrid from a user control.

    Thanks in advance 

     

     

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 15, 2012 @ 10:27
    Lee Kelleher
    0

    Hi qz2rg4,

    Which version of Umbraco and uComponents are you using?

    Can you expand on how you would like to use the DataTypeGrid within your user-control? As in did you want to reuse a specific instance of it (from a content node / property), or just add the control to the page? (but then where would you want store the data for it?)

    Cheers, Lee.

  • Anton Oosthuizen 206 posts 486 karma points
    Nov 15, 2012 @ 10:36
    Anton Oosthuizen
    0

    Hi.

    I'm using uComponents 5.

    And I want to add data to a spesific property on a member node.

    Thanks

     

     

  • Anton Oosthuizen 206 posts 486 karma points
    Nov 15, 2012 @ 10:38
    Anton Oosthuizen
    0

    So far I  can see the info using the following code 

      string s = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(userName).getProperty("transactionHistory").Value.ToString();
    
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 15, 2012 @ 10:55
    Lee Kelleher
    0

    Hi,

    There's a wiki article on how to use MNTP on a user-control - which cover the overall principle.

    I tend to use the following code - which I've re-apdated to use a Member instead of a content Node.  Here's the code snippet:

    private umbraco.interfaces.IDataType _dataType;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // get the property value (from the member)
        var userName = "username"; // get this from wherever
        var member = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(userName);
        var property = member.getProperty("transactionHistory");
    
        // get the data-type
        var factory = new umbraco.cms.businesslogic.datatype.controls.Factory();
        var dataType = factory.DataType(new Guid(uComponents.Core.DataTypes.DataTypeConstants.DataTypeGridId));
    
        // set the values
        dataType.DataTypeDefinitionId = 1234; // you'll need to fine out the data-type id
        dataType.DataEditor.Editor.ID = property.PropertyType.Alias;
        dataType.Data.Value = property.Value;
    
        this._dataType = dataType;
    
        // add the data-type editor control
        this.Controls.Add(dataType.DataEditor.Editor);
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        // get the data-type
        var dataType = this._dataType;
    
        // get the property value (from the member)
        var userName = "username"; // get this from wherever
        var member = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(userName);
        var property = member.getProperty("transactionHistory");
    
        // save the value
        dataType.Data.PropertyId = property.Id;
        dataType.DataEditor.Save();
    
        // re-save the member?
        member.Save();
    }

    The idea is to get the member's property, assign it to the DataType, then add it to the page.  Then on PostBack (OnClick event), re-get the member, re-load the property (for the Id) and assign that back to the DataType and then save it.

    Obviously this code hasn't been tested (it is based on code that I've used personally and does work) ... so may need some tweaking, etc.

    Good luck!

    Cheers, Lee.

  • Anton Oosthuizen 206 posts 486 karma points
    Nov 21, 2012 @ 10:29
    Anton Oosthuizen
    0

    Hi Lee

    Thanks. I will surely need this in the future, but what I'm looking for is to manipulate the data directly.

    Should I pull the property in to XMLDocument and work the data this way or is there a better way of accomplishing this ?

     

    Thanks

     

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 21, 2012 @ 11:18
    Lee Kelleher
    0

    Hi qz2rg4,

    Yes, probably best to manipulate as an XmlDocument.

    An alternative way could be to load it into a List<uComponents.DataTypes.DataTypeGrid.Model.StoredValueRow> ... but then not sure how you'd get the data back out of it.  Depends on how much you wanted a strongly-typed object/collection.

    Cheers, Lee.

  • Ove Andersen 435 posts 1541 karma points c-trib
    Jan 05, 2013 @ 11:10
    Ove Andersen
    0

    @qz2rg4

     The best way is to do as you proposed, read it out as an XmlDocument, edit and then save it back.

    I might create a better way of doing it in the future, but its not on the top of the list right now. (unless a lot of people request this)

Please Sign in or register to post replies

Write your reply to:

Draft