Monday, July 11, 2005

Moojjoo Blog

Moojjoo Blog

Learning more about C# logic everyday. I needed a dropdown that would display dates in a reverse order so how do you do this.

for (int i = DateTime.Now.Year; i >= 2000; i--)

Simple thanks to the MVP at the forums in MSDN

David Anton
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"Moojjoo" wrote:

I am building a dropdown select box for year and want to render the dropdown
in reverse order. Using VB I could use step, but I am unsure how to do this
in C#

Any help would be great.

if (!this.IsPostBack)
for (int i = 2000; i <= DateTime.Now.Year; i++)
int intSubtractTerm = 0;
ListItem newListItem = new ListItem();
intYear = DateTime.Now.Year;
intSubtractTerm = intYear - i;
intYear = intYear - intSubtractTerm;
newListItem.Value = intYear.ToString();
newListItem.Text = intYear.ToString();
Post a Comment