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 3286548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:23:34+00:00 2026-05-17T20:23:34+00:00

I am trying to extract month and year from database and show it as

  • 0

I am trying to extract month and year from database and show it as selected in the dropdown. Ex: Month and year, consider 2 and 2013. I want the dropdown expmonth to show Febraury and expyear as 2013 when the page is loaded.
When i tried the below code, it did not show me 2 and 2013 instead showed Jan and 2010 which is default. Where do you think i am doing wrong, guys??

<asp:DropDownList ID="ddExpMonth" runat="server" TabIndex="19" Width="80px" CausesValidation="True">
</asp:DropDownList>
&nbsp;
<asp:DropDownList ID="ddExpYear" runat="server" TabIndex="20" Width="57px" CausesValidation="True">
</asp:DropDownList>

LoadExpDateInfo();
ddExpMonth.SelectedIndex = expmonth-1;
ddExpMonth.SelectedItem.Value = expmonth.ToString();

ddExpYear.SelectedIndex = expyear;
int currentyear = Convert.ToInt16(DateTime.Now.Year);
int diff = expyear - currentyear;
ddExpYear.SelectedItem.Value = diff.ToString();

expyear and expmonth values are retrieved from database.


    private void LoadExpDateInfo()
    {
        string[] arrMonths = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
        ListItem item;
        for (int i = 0; i < 12; i++)
        {
            item = new ListItem();
            item.Text = arrMonths[i];
            item.Value = Convert.ToString(i + 1);
            ddExpMonth.Items.Add(item);
        }

        for (int i = -1; i < 10; i++)
        {
            item = new ListItem();
            item.Text = Convert.ToString(System.DateTime.Now.AddYears(1).AddYears(i).Year);
            item.Value = Convert.ToString(System.DateTime.Now.AddYears(1).AddYears(i).Year);
            ddExpYear.Items.Add(item);
        }
    }

Thanks for all your help guys. I appreciate your time 🙂

  • 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-17T20:23:34+00:00Added an answer on May 17, 2026 at 8:23 pm

    You should only have to set the selected index, not the value of the selected item. The following should work, although I’d expect your initial code to have some effect as well. Are you setting the selected index early enough in the page lifecycle? You can test this by just setting the selected index to a constant value (i.e. 3) and see if it defaults to April.

    LoadExpDateInfo(); 
    ddExpMonth.SelectedIndex = expmonth-1; 
    
    int currentyear = Convert.ToInt16(DateTime.Now.Year); 
    int diff = expyear - currentyear;
    ddExpYear.SelectedIndex = diff;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to extract a line from wget's result but having trouble with it.
I am trying to extract a table of values from an excel (2003) spreadsheet
I'm trying to extract all matches from a EBML definition, which is something like
I'm trying to extract the domain name from a string in C#. You don't
I'm trying to parse a html page and extract 2 values from a table
I'm trying to reproduce this SQL query I used with ActiveRecord: Post.all(:conditions => [EXTRACT(MONTH
I'm trying to extract the price from the bellow html page/link using php cURL
Using Prototype, I'm trying to extract a piece of text from the DOM -
I am trying to extract a gif image embedded as a resource within my
I am trying to extract a certain part of a column that is between

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.