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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T08:57:59+00:00 2026-05-19T08:57:59+00:00

Actually i am displaying months in first list on selecting the month if the

  • 0

Actually i am displaying months in first list on selecting the month if the value of month is other than 31 it shows at top otherwise it shows jan at top how to show the other one?

Here is code:

Code behind:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList2.Items.Clear();
    for (int i = 1; i <= int.Parse(DropDownList1.SelectedValue); i++)
    {
        DropDownList2.Items.Add(new ListItem("" + i));
    }
}

Designer source:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem Value="31">Jan</asp:ListItem>
    <asp:ListItem Value="29">Feb</asp:ListItem>
    <asp:ListItem Value="31">Mar</asp:ListItem>
    <asp:ListItem Value="30">April</asp:ListItem>
    <asp:ListItem Value="31">May</asp:ListItem>
    <asp:ListItem Value="30">June</asp:ListItem>
    <asp:ListItem Value="31">July</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>

Problem is:

If i select march or may or any item with value 31 jan is shown at to while in other case the selected one is shown.

  • 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-19T08:58:00+00:00Added an answer on May 19, 2026 at 8:58 am

    Values of ListItems should be unique.

    Default selected item is Jan (value = 31), so everything will work fine when you click on items with another values (29 and 30).

    When you click on Mar, May, July (value = 31), then Jan becomes selected.

    To achieve the behavior you want, use another approach.


    The best solution is:

    using System.Linq;
    
    int count =  DateTime.DaysInMonth(
         DateTime.Today.Year,
         int.Parse(DropDownList2.SelectedIndex + 1)); // sic!
    
    DropDownList2.Items.AddRange(
        Enumerable.Range(1, count)
            .Select(i => new ListItem(i.ToString()))
            .ToArray());
    

    So you don’t need to hard-code anything! Everything is already in .NET FCL. Just determine month’s number from it’s index into the list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a databound listbox which is actually displaying two columns of data. It
actually i am displaying a pop up with ok cancel button when user clicks
Actually I am developing one application in that when application run first time it
Actually i am displaying events in calendar and for that i am adding subviews
I have ObservableCollection<Foo> that is bound to an ItemsControl (basically displaying a list). Foo
Actually, This is working fine.. but i want the parent value. not a child
I have a small issue actually getting variable to show - let alone how
I'm new to Sencha Touch and the Ext JS logic. Actually, I'm displaying a
I would like the autocomplete to display a footer which says Displaying top 5
I have a web application that has a grid displaying a paged list of

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.