I have been going round in circles trying to get this to work.
My tree structure is:
Home - Galleries - Competitions - Competition Year - Competition
- Competition - Competition Year - Competition - Competition
The competition document type has a property within it for a "close off" date.
And so what I am wanting to do within my User Control is output a select list of all competitions that have a close off date in the future - ie competitions still open for entering.
From sniffing around the forums, etc I have tried the following:
foreach (XmlNode xn in xnList) { selMembComp.Items.Add(new ListItem(xn.Attributes["id"].Value, xn.Attributes["nodeName"].Value)); }
The above is an initial attempt to get all competitions in the select list - after I get that working I will look to add the additional conditional checking for the date.
Can anyone please advise where I am going wrong - I am off to bed as I have a headache (self created through frustration)!
Would the method GetNodesFromXpath() in this Helper Class be of any use ? (an updated version of this class will be included in the next uComponents release)
foreach (Node competition in UmbracoHelper.GetNodesFromXpath("/competition")) { selMembComp.Items.Add(newListItem(competition.Name, competition.Id)); }
You'll just need to add the filtering to your XPath expression to get the required competition nodes.
Ismail - I am using a user control as I have an image upload component - step 1 is to select the competition, step 2 (when I get that far!) is to upload images to the chosen competition.
Hendy - I downloaded your helper class but it didn't work :-( , looked like a nice class tho with useful methods
So I tried the following and managed to get the select list populating as desired
But being hard coded isn't a good thing so did a bit more Googling and stumbled across a forum post can't find geo datatype and Tmi Geyssens contrubutions regarding 4.5 schema made me realise how simple the required code is . . .
User Control xPath Nightmare
Hi there
I have been going round in circles trying to get this to work.
My tree structure is:
Home
- Galleries
- Competitions
- Competition Year
- Competition
- Competition
- Competition Year
- Competition
- Competition
The competition document type has a property within it for a "close off" date.
And so what I am wanting to do within my User Control is output a select list of all competitions that have a close off date in the future - ie competitions still open for entering.
From sniffing around the forums, etc I have tried the following:
The above is an initial attempt to get all competitions in the select list - after I get that working I will look to add the additional conditional checking for the date.
Can anyone please advise where I am going wrong - I am off to bed as I have a headache (self created through frustration)!
Thanks in anticipation
Nigel
Nigel,
Is there reason why you are doing this in code why not do it in xslt macro?
Regards
Ismail
Hi Nigel,
Would the method GetNodesFromXpath() in this Helper Class be of any use ? (an updated version of this class will be included in the next uComponents release)
You'll just need to add the filtering to your XPath expression to get the required competition nodes.
HTH,
Hendy
Hi Ismail and Hendy
Thanks for your replies.
Ismail - I am using a user control as I have an image upload component - step 1 is to select the competition, step 2 (when I get that far!) is to upload images to the chosen competition.
Hendy - I downloaded your helper class but it didn't work :-( , looked like a nice class tho with useful methods
So I tried the following and managed to get the select list populating as desired
XmlNodeList xnList = xmlDoc.SelectNodes("/root/Home/galleryParent/competitionParent/competitionYear/competition");
But being hard coded isn't a good thing so did a bit more Googling and stumbled across a forum post can't find geo datatype and Tmi Geyssens contrubutions regarding 4.5 schema made me realise how simple the required code is . . .
XmlNodeList xnList = xmlDoc.SelectNodes("//competition");
This is simply selecting all competition nodes - I just have to add the logic to check for the date property . . .
Yet again 2 lessons learnt:
1. Umbraco rocks and more often than not the answer is blindingly simple.
2. A good nights sleep always helps
Regards
Nigel
Hi Hendy
I have just revisited this and have made some progress, so will persevere with your Helper class - definitely liking the cleanliness of code.
The following is now outputting all competition nodes in the select list (double slash is where I was going wrong previously).
So the next step is to get the filtering working on the competition nodes based on the competition close date property.
I tried the following but it returned no items
Obviously the close off date value isn't being recognised as a date value
Can anyone please enlighten me as to how to do a date comparison ?
Thanks
Nigel
I have just Googled and read that date format isn't recognised and you must convert dates to numbers and compare that way.
So I tried the following but am getting no results - can anyone advise where I am going wrong ?
foreach (Node competition in UmbracoHelper.GetNodesFromXpath("//competition[number(concat(substring(/competitionCloseDate, 1, 4), substring(/competitionCloseDate, 6, 2), substring(/competitionCloseDate, 9, 2))) >= number(" + todaysDate + ")]"))
I read the index starts at 1 and with the date being output as 2010-11-30T00:00:00 I assume I have the indexes correct for the substring
OK - I have cracked it . . .
foreach (Node competition in UmbracoHelper.GetNodesFromXpath("//competition[number(concat(substring(competitionCloseDate, 1, 4), substring(competitionCloseDate, 6, 2), substring(competitionCloseDate, 9, 2))) >= number(" + todaysDate + ")]")) { selMembComp.Items.Add(new ListItem(competition.Name.ToString(), competition.Id.ToString())); }
So Hendy - a tick for you - your Help Class is wicked. Now to get me media issue working
is working on a reply...