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.
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);
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
Did you have a look at the GridRowCollection that is used in the example. Maybe it has a .Add method you can use.
Jeroen
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
If anyone else needs help on this one I achieved it with the below:
nice code, thanks, Damien! But only one question: which reference can I use to work with "GridRowCollection"? cant find it :(
I would also like to know what directive or reference is needed for GridRowCollection.
is working on a reply...