I need to create an unordered list of dates for a news items archive… It should look like this
2011
Dec
Nov
etc..
2010
Dec
Nov
etc...
Older
Here is what I have so far..
Dim StartYear As DateFormat = Date.Now.Year
Dim EndYear As DateFormat = Date.Now.Year - 2
ltlArchives.Text = "<ul id=""ArchivesYears"">"
For StartYear = StartYear To EndYear Step -1
ltlArchives.Text = ltlArchives.Text + "<li>" + StartYear.ToString + "</li>"
Next
ltlArchives.Text = ltlArchives.Text + "<li>Other</li>"
ltlArchives.Text = ltlArchives.Text + "</ul>"
I can carry on with this adding in the for loops for months nested under each year however it doesn’t seem very practical and will generate links for months even if there are no news item entries…
Is there a way I can build this tree automatically and only include the years/months that have news entries. I can pull a list of SQL Server timestamps from the DB for all the news items and then would like to populate the list based on that…
Can someone point me in the right direction?
You need to find out years and months with news item from SQL Server – say using distinct query. For example, assuming
PostedDatecolumn indicates entry date for new itemThis query will give you years and months that have news items. Now bind it with say repeater control to get what you want.