I have a dashboard usercontrol in backend, where I want to list events from the content section with the properties. So I need to get the EventCalendar node and list the nodes in the gridview.
using umbraco.presentation.nodeFactory;
...
var n = Node.GetCurrent();
GridView1.DataSource = n.ChildrenAsTable();
GridView1.DataBind();
I should be something like the code above if it was placed on frontend..
But in this case I need to get a specific node id or doctype, which child nodes I can use in the gridview control. And then use e.g. nodename, date and other properties in the different columns.
using umbraco.presentation.nodeFactory; ... var specificNode = new Node(1133);
var childNodes = specificNode.Children;
foreach (Node childNode in childNodes)
{
foreach (Node childNode in childNodes)
{
GridView1.DataSource = specificNode.ChildrenAsTable();
GridView1.DataBind();
}
}
which gives me:
Id
NodeName
NodeTypeAlias
CreateDate
UpdateDate
CreatorName
WriterName
Url
Specifik url
Beskrivelse
Nøgleord
Skjul fra menu
Titel
Videredireger til
1139
2011
DateFolder
10/08/2011 01:20:43
16/08/2011 23:47:24
admin
admin
/aktuelt/events/2011.aspx
I then need to get a couple of level more down, as my content stucture is: EventCalender (id=1133) > 2011 (DateFolder) > August (DateFolder) > Event
Someone who knows how I get the nodes with use Event doc type? and perhaps specify which properties to use in gridview columns?
You can get the current node in the Umbraco back-end via Request.Querystring["id"], but I have heard that this is not the best practice. Not sure what is at this point,but it will definitely get you the ID of the node so you can query the child nodes.
I'm not sure I can use the currentNode in this case as the the usercontrols is placed in aa dashboard tab in the content section..
so that's why I have used var specificNode =newNode(1133); to get the first level of the Event Calendar.. then I think I somehow have to loop trough the childnodes to get the ones with Event as doc type.
And then somehow specify which properties to use, cause when using GridView1.DataSource= specificNode.ChildrenAsTable(); I just think it fill in available properties for that node, but what I need is more like nodeName, startDate, endDate and something like that.
How can I fill a gridview with child nodes properties using the nodefactory?
I have this structure in content section: Event Calendar (id=1133) > 2011 > August > Event ... where I want to specify which properties from the Event nodes that shall be in each column of gridview.
You can set AutoGenerateColumns in gridview to false and only define the columns you want to show by either using ItemTemplates, or Boundfields. Reference the variable you want by property name using Eval();
To Bjame, when you perform your databind, you are using the properties of the node, but when using Eval() from the aspx, you are using the name associated to the DataItem, such as if you use a DataTable to bind the gridview to, the Eval() would use the column name from the DataRow.
Ciaran, yes, you can use to edit the records. You would use the GridView Edit feature that would be associated to a c sharp function that would get the row and update the properties accordingly.
When you have multiple records in a record-set, yes, you would use the bind, such as looping over all content nodes, Otherwise, you can set the value to a literal or textbox from code-behind if always just one record.
To clarify (as I am having the same issue), are you saying that you cannot use properties of your document types in an Eval() in the front end, e.g. if I have a document type of news and add a property "NewsDate", I cannot use:
<%#Eval("NewsDate")%>
in my code?
If so, is the best way around this to have a literal LtrNewsDate and then to have on ItemDataBound event which has the following code (VB I'm afraid!):
Dim oNode As Node = e.Item.DataItem Dim LtrNewsDate As Literal = e.Item.FindControl("LtrNewsDate") LtrNewsDate.Text = oNode.GetProperty("NewsDate").Value
Ok. I've found another way around my post above, but I'm a bit confused as to why it works like this.
In my example above, my document type had a property with:
Name: News Date Alias: newsDate
If I use the alias like so:
#Eval("newsDate")%>
then it doesn't work.
If I use the name:
#Eval("News Date")%>
then it works fine!
This seems crazy to me, as you might well want to change the name on your interface and this would mean changing all your code! Am I getting something wrong here, or is this the case??
Jenni, if you are using a gridview, then you could create a DataTable that holds your property values, then Eval("column") the DataTable row on the aspx.
C#:DataTable dt = new DataTable("myDataTable");dt.Columns.Add("col1")DataRow = dt.NewRow();foreach(Node n in nyNodes.Children){row["col1"] = document.GetProperty("foo").Value;dt.Rows.Add(row);}myGridview.DataSource = dt;myGridview.DataBind();aspx:<asp:literal ID="foo" Text='<%# Eval("foo") %>' runat="server"></asp:Literal>
If you are not using a GridView or Reapeter and have just one value to output, then you could use your method.
List events in GridView
Hi..
I have a dashboard usercontrol in backend, where I want to list events from the content section with the properties.
So I need to get the EventCalendar node and list the nodes in the gridview.
I should be something like the code above if it was placed on frontend..
But in this case I need to get a specific node id or doctype, which child nodes I can use in the gridview control.
And then use e.g. nodename, date and other properties in the different columns.
Bjarne
I have this in my code:
which gives me:
I then need to get a couple of level more down, as my content stucture is: EventCalender (id=1133) > 2011 (DateFolder) > August (DateFolder) > Event
Someone who knows how I get the nodes with use Event doc type? and perhaps specify which properties to use in gridview columns?
Bjarne
You can get the current node in the Umbraco back-end via Request.Querystring["id"], but I have heard that this is not the best practice. Not sure what is at this point,but it will definitely get you the ID of the node so you can query the child nodes.
I'm not sure I can use the currentNode in this case as the the usercontrols is placed in aa dashboard tab in the content section..
so that's why I have used var specificNode =newNode(1133); to get the first level of the Event Calendar.. then I think I somehow have to loop trough the childnodes to get the ones with Event as doc type.
And then somehow specify which properties to use, cause when using GridView1.DataSource= specificNode.ChildrenAsTable(); I just think it fill in available properties for that node, but what I need is more like nodeName, startDate, endDate and something like that.
I think I shall be something like this http://mosesofegypt.net/post/Building-a-grouping-Grid-with-GridView-and-ASPNET-AJAX-toolkit-CollapsiblePanel.aspx where you can expand each event and see who is coming for that event.
Bjarne
Any ideas? :)
How can I fill a gridview with child nodes properties using the nodefactory?
I have this structure in content section: Event Calendar (id=1133) > 2011 > August > Event ... where I want to specify which properties from the Event nodes that shall be in each column of gridview.
Bjarne
I managed to show the event nodes in gridview this way:
How do I choose which properties to show in each gridview column? Right now I get all properties for the event node listed in gridview..
Bjarne
You can set AutoGenerateColumns in gridview to false and only define the columns you want to show by either using ItemTemplates, or Boundfields. Reference the variable you want by property name using Eval();
Okay thanks..
It worked with nodeName, but I get an error that it can't find the property, when I use the aliases:
I guess something more has to be done to get the other properties than just using <%# Eval ("propertyAlias") %>
Bjarne
Hi, I was wondering will this work for editing the records too?
I am quite new to Umbraco so any pointers would be appreciated.
Thanks,
Ciaran.
To Bjame, when you perform your databind, you are using the properties of the node, but when using Eval() from the aspx, you are using the name associated to the DataItem, such as if you use a DataTable to bind the gridview to, the Eval() would use the column name from the DataRow.
Ciaran, yes, you can use to edit the records. You would use the GridView Edit feature that would be associated to a c sharp function that would get the row and update the properties accordingly.
Hi Don
Okay, so I should use Bind() method instead, when I want to use a property of the node?
Bjarne
When you have multiple records in a record-set, yes, you would use the bind, such as looping over all content nodes, Otherwise, you can set the value to a literal or textbox from code-behind if always just one record.
To clarify (as I am having the same issue), are you saying that you cannot use properties of your document types in an Eval() in the front end, e.g. if I have a document type of news and add a property "NewsDate", I cannot use:
in my code?
If so, is the best way around this to have a literal LtrNewsDate and then to have on ItemDataBound event which has the following code (VB I'm afraid!):
I'd love it if you could let me know!
Thanks, Jenni
Ok. I've found another way around my post above, but I'm a bit confused as to why it works like this.
In my example above, my document type had a property with:
If I use the alias like so:
#Eval("newsDate")%>
then it doesn't work.
If I use the name:
#Eval("News Date")%>
then it works fine!
This seems crazy to me, as you might well want to change the name on your interface and this would mean changing all your code! Am I getting something wrong here, or is this the case??
Thanks,
Jenni
Jenni, if you are using a gridview, then you could create a DataTable that holds your property values, then Eval("column") the DataTable row on the aspx.
C#:DataTable dt = new DataTable("myDataTable");dt.Columns.Add("col1")DataRow = dt.NewRow();foreach(Node n in nyNodes.Children){row["col1"] = document.GetProperty("foo").Value;dt.Rows.Add(row);}myGridview.DataSource = dt;myGridview.DataBind(); aspx:<asp:literal ID="foo" Text='<%# Eval("foo") %>' runat="server"></asp:Literal>If you are not using a GridView or Reapeter and have just one value to output, then you could use your method.
Hope this helps!
is working on a reply...