Asp:Repeater used to iterate comments as stored in umbraco..
I am trying to display a list of comments in a thread, and have decided to use an asp:repeater to iterate over the comments in a given thread to display them. I have added properties of 'userName', 'postedDate' and 'bodyText' to the comments document type, which I am trying to pull out and display with a repearter.
The error that I get when I try to execute this is '
System.Data.DataRowView' does not contain a property with the name 'userName'
I guess this is becuase I can only call generic node types using the eval thingy on the ascs control?
So can anyone tell me how I would successfully call the node's custom properties from here? I imagine its something like the getProperty("property").Value code but need a hand in the right direction!
Asp:Repeater used to iterate comments as stored in umbraco..
I am trying to display a list of comments in a thread, and have decided to use an asp:repeater to iterate over the comments in a given thread to display them. I have added properties of 'userName', 'postedDate' and 'bodyText' to the comments document type, which I am trying to pull out and display with a repearter.
Here is my repeater:
And here is my code behind:
The error that I get when I try to execute this is '
System.Data.DataRowView' does not contain a property with the name 'userName'
I guess this is becuase I can only call generic node types using the eval thingy on the ascs control?
So can anyone tell me how I would successfully call the node's custom properties from here? I imagine its something like the getProperty("property").Value code but need a hand in the right direction!
Bob,
You need to cast to Node then call getProperty
<%#((Node)Container.DataItem).getProperty("userName").Value.ToString()%>
However safer way would be to create a method in code behind with signature like
protected string GetNodeProperty(Node n, string propertyToGet){
if(n.getProperty(propertyToGet)!=null){
return n.getProperty.(propertyToGet).ToString();
}
return string.Empty
}
Regards
Ismail
Thanks Ismail,
I used the code like this (the only difference being I have written a full library path to the node, which I'm unsure will affect anything):
<%#((umbraco.presentation.nodeFactory.Node)Container.DataItem).GetProperty("bodyText").Value.ToString()%>
But I am getting the following error message now:
Unable to cast object of type 'System.Data.DataRowView' to type 'umbraco.presentation.nodeFactory.Node'.
Any ideas?
On a side note: When I high5 someone it appears to have gone whenever I refresh the page?!
ok I got it working for me in case anyone else ever wants to do similar.
Taking Ismail's suggestion I came up with this method to put in the code behind:
protected string GetNodeProperty(int Id, string propToGet) {
Node n = new Node(Id);
if (n.GetProperty(propToGet) != null) {
return n.GetProperty(propToGet).Value.ToString();
}
return string.Empty;
}
Which I was then able to call in the repeater like this:
Posted by:on
is working on a reply...