Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:54:41+00:00 2026-05-26T18:54:41+00:00

I have a dropdownlist in ASP.NET Webforms that I want to calculate how many

  • 0

I have a dropdownlist in ASP.NET Webforms that I want to calculate how many years ago a certain year was.

In the first line 2002 is the current year -9 and has to be the value, and 9 is the text that is visibel and shows how many years ago 2002 was.

2002 9
2003 8
2004 7
2005 6
2006 5
2007 4
2008 3
2009 2
2010 1
2011 0 

And I want 5 to be the preselected. How Do I do that? First of I dont know how to add a hidden Value (ex. 2002 to the visibel 9).

This is my start… Not far, I know…

 {
        int CT = DateTime.Now.Year;
        int CT10 = CT - 10;

        for (int i = CT10; i <= CT; i++)

        {
            ddlBirthYear.Items.Add(i.ToString());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:54:41+00:00Added an answer on May 26, 2026 at 6:54 pm

    You can use a ListItem to add a text and value

    ddlBirthYear.Items.Add(new ListItem("text", "value"));
    

    You can select that with

    ddlBirthYear.SelectedValue = "5";
    

    So your loop will look like this:

    {
      int CT = DateTime.Now.Year;
      int CT10 = CT - 10;
    
      for (int i = CT10; i <= CT; i++)
      {
        ddlBirthYear.Items.Add(new ListItem(i.ToString(), (CT-i).ToString()));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET DropDownList control that retrieves the first and last name from
I have a dropdownlist (asp.net) and when user change the selection and i want
I have a DropDownList on an ASP.NET master page and I want to change
I have two dropdownlist which shows places in my asp.net MVC(C#) application. The First
I have a DropDownList inside a repeater control in an ASP.NET page that has
I have a dropdownlist in my asp.net page. I want to display database data
I have a ASP.NET Application with a DropDownList and I want it fill with
I have an ASP.NET Web Application that has a dropdownlist which pulls up student
I have a function that fills creates dropdownlist in ASP.NET MVC. public static MvcHtmlString
I have an ASP.NET webform on which I use a DropDownList control to allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.