Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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

  • Damien 25 posts 138 karma points
    Mar 24, 2014 @ 17:27

    DataType Grid - integration C# adding rows


    I have studied the documentation here:

    It shows how to manipulate existing data stored using the Grid datatype but not how to add new rows programmatically.

    Has anyone done this via the content service, and if so could show an example please?

    Many Thanks


  • Jeroen Breuer 4817 posts 11905 karma points admin mvp c-trib
    Mar 24, 2014 @ 17:48
    Jeroen Breuer

    Did you have a look at the GridRowCollection that is used in the example. Maybe it has a .Add method you can use. 


  • Damien 25 posts 138 karma points
    Mar 24, 2014 @ 17:58

    Hi Jeroen,

    It does yes, I've hooked the below up

    GridCell gc = new GridCell(); gc.Value = "TEST";

    GridRow gr = new GridRow(); gr.Add(gc);


    It also has an insert method, I'm unsure which one to use, I have an existing structure defined for the datatype grid and just need to add rows to it, will keep playing and let you know.


  • Damien 25 posts 138 karma points
    Mar 25, 2014 @ 11:33

    If anyone else needs help on this one I achieved it with the below:

        var contentService = ApplicationContext.Current.Services.ContentService;
        var content = contentService.GetById(1343);
        var data = new GridRowCollection(content.GetValue("orderItems").ToString()); //DataType Alias
        int gridRowCount = data.Count();
        GridCell gcProductName = new GridCell();
        gcProductName.Value = "Product Name";
        gcProductName.Alias = "productName";
        GridCell gcProductGategory = new GridCell();
        gcProductGategory.Value = "Category Name";
        gcProductGategory.Alias = "category";
        GridRow gr = new GridRow();
        data.Insert(gridRowCount, gr);
        content.SetValue("orderItems", data.ToString());
        var result = contentService.SaveAndPublish(content);
  • Andrey Koms 1 post 21 karma points
    Oct 14, 2015 @ 13:47
    Andrey Koms

    nice code, thanks, Damien! But only one question: which reference can I use to work with "GridRowCollection"? cant find it :(

Please Sign in or register to post replies

Write your reply to: