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?)
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.
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.
uComponents DatatypeGrid - Add data via user control
Hi
How will I go about adding data to DatatypeGrid from a user control.
Thanks in advance
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.
Hi.
I'm using uComponents 5.
And I want to add data to a spesific property on a member node.
Thanks
So far I can see the info using the following code
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:
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.
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
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.
@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)
is working on a reply...