Dear All,
Please Help Me i want to write a code in asp.net using c# to list previous, current and next 3 years in dropdownlist dynamically at page load without using table.
Thanks and regards,
Dipti
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Sep 6, 2010, 4:56 PM
int i = -1;
do
{
comboBox1.Items.Add(DateTime.Now.AddYears(i).Year.ToString());
i = i + 1;
} while (i<4);
Pasan RatnayakePosted Sep 6, 2010, 1:33 AM
This is actually of no problem to be helped. This is pretty easy to attain if you looked at the 3 basic things: form_load event, adding/removing items in a combobox, getting current year. Make sure you try something before you post for help =]
int previousYearsCount = 3;
int afterYearsCount = 3;
comboBox1.Items.Clear();
int currentYear = DateTime.Now.Year;
for (int addedYear = currentYear - previousYearsCount; addedYear <= currentYear + afterYearsCount; addedYear++)
{
comboBox1.Items.Add(addedYear);
}
This is simple logic where you can use in your form load event.
Hope this helps.