Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 18, 2011 @ 13:43
    Bjarne Fyrstenborg
    0

    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.

    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.

    Bjarne

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 18, 2011 @ 17:10
    Bjarne Fyrstenborg
    0

    I have this in my code:

    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:

    IdNodeNameNodeTypeAliasCreateDateUpdateDateCreatorNameWriterNameUrlSpecifik urlBeskrivelseNøgleordSkjul fra menuTitelVideredireger 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?

    Bjarne

  • Don Ross 28 posts 49 karma points
    Aug 19, 2011 @ 12:58
    Don Ross
    0

    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.

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 19, 2011 @ 13:20
    Bjarne Fyrstenborg
    0

    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

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 22, 2011 @ 14:40
    Bjarne Fyrstenborg
    0

    Any ideas? :)

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 23, 2011 @ 20:25
    Bjarne Fyrstenborg
    0

    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

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 24, 2011 @ 14:39
    Bjarne Fyrstenborg
    0

    I managed to show the event nodes in gridview this way:

    Node specificNode = new Node(1133);
    Nodes children = specificNode.Children;
    
    foreach (Node child in children)
    {
    foreach (Node events in child.Children)
    {
    
    GridView1.DataSource = events.ChildrenAsTable("Event");
    GridView1.DataBind();
    } }

    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 

  • Don Ross 28 posts 49 karma points
    Aug 26, 2011 @ 13:40
    Don Ross
    0

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

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Aug 26, 2011 @ 21:11
    Bjarne Fyrstenborg
    0

    Okay thanks..

    It worked with nodeName, but I get an error that it can't find the property, when I use the aliases:

    <asp:GridView ID="GridView1" runat="server">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("nodeName") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
    
                </Columns>
                </asp:GridView>

    I guess something more has to be done to get the other properties than just using <%# Eval ("propertyAlias") %>

    Bjarne

  • Ciaran McCusker 54 posts 93 karma points
    Jan 20, 2012 @ 12:01
    Ciaran McCusker
    0

    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. 

  • Don Ross 28 posts 49 karma points
    Jan 20, 2012 @ 14:33
    Don Ross
    0

    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.

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Jan 20, 2012 @ 14:39
    Bjarne Fyrstenborg
    0

    Hi Don

    Okay, so I should use Bind() method instead, when I want to use a property of the node?

    Bjarne

  • Don Ross 28 posts 49 karma points
    Jan 21, 2012 @ 13:57
    Don Ross
    0

    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.

  • Jenni Marsh 26 posts 46 karma points
    Jan 31, 2012 @ 11:53
    Jenni Marsh
    0

    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 

    I'd love it if you could let me know!

    Thanks, Jenni

  • Jenni Marsh 26 posts 46 karma points
    Jan 31, 2012 @ 12:25
    Jenni Marsh
    0

    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??

    Thanks,
    Jenni 

  • Don Ross 28 posts 49 karma points
    Jan 31, 2012 @ 12:33
    Don Ross
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft