Copied to clipboard

Flag this post as spam?

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


  • Damien 36 posts 162 karma points
    Mar 24, 2014 @ 17:27
    Damien
    0

    DataType Grid - integration C# adding rows

    Hi,

    I have studied the documentation here: http://ucomponents.org/data-types/datatype-grid/integration/

    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

    Damien

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 24, 2014 @ 17:48
    Jeroen Breuer
    0

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

    Jeroen

  • Damien 36 posts 162 karma points
    Mar 24, 2014 @ 17:58
    Damien
    0

    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);

    data.Add(gr);

    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.

    Thanks

  • Damien 36 posts 162 karma points
    Mar 25, 2014 @ 11:33
    Damien
    101

    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();
        gr.Add(gcProductName);
        gr.Add(gcProductGategory);
    
        data.Insert(gridRowCount, gr);
    
        content.SetValue("orderItems", data.ToString());
    
        var result = contentService.SaveAndPublish(content);
    
  • Andrey Koms 1 post 22 karma points
    Oct 14, 2015 @ 13:47
    Andrey Koms
    1

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

  • Echo Train 16 posts 106 karma points
    Mar 15, 2018 @ 19:03
    Echo Train
    0

    I would also like to know what directive or reference is needed for GridRowCollection.

Please Sign in or register to post replies

Write your reply to:

Draft