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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:25:41+00:00 2026-06-07T05:25:41+00:00

I used to think my c# programming wasn’t too bad, but today I am

  • 0

I used to think my c# programming wasn’t too bad, but today I am seriously questioning my head, something so small is defeating me…

I am trying to get a DropDownList to behave but we are not getting on today. I have a simple DropDownList in an ascx control which is dynamically loaded into an aspx page

<asp:DropDownList ID="ddl_SortBy" runat="server" AutoPostBack="true">             
  <asp:ListItem Value="0">Sort Alphabetically A to Z</asp:ListItem>
  <asp:ListItem Value="1">Sort Alphabetically Z to A</asp:ListItem>
</asp:DropDownList>

and some code behind..

    private short SortBy = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.ddl_SortBy.SelectedIndex = -1;
        this.ddl_SortBy.SelectedIndexChanged += new EventHandler(ddl_SortBy_SelectedIndexChanged);

        if (!IsPostBack)
            SearchDirectory();
    }

    public void ddl_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        SortBy = Convert.ToInt16(this.ddl_SortBy.SelectedItem.Value);
        SearchDirectory();
    }

I can never get the first item to trigger the selected index change event – as the SearchDirectory() function is not called. I can understand that it’s possibly the case that when the control loads the first item IS selected so when selecting, the index isn’t actually changing.

I have tried setting the selected item index to -1, and ClearSelection() on page load, but no luck.

Any ideas? Thanks

  • 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-06-07T05:25:42+00:00Added an answer on June 7, 2026 at 5:25 am

    You are always resetting the SelectedIndex to -1 on every postback:

    this.ddl_SortBy.SelectedIndex = -1;
    

    So put that also in the postback-check:

    if (!IsPostBack)
    {
        this.ddl_SortBy.SelectedIndex = -1;
        SearchDirectory();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not very used to programming with flags, but I think I just found
I think I may have used a repeater when I should have used something
I think I may misunderstand why the with command is used. But can any
I used to think that Hive was just a SQL-like programming language used to
I used to think I was a reasonably intelligent person. apple's threading programming guide,
I'm used to doing Java programming, where you never really have to think about
I've been using Think Python to learn programming over the last few days. Today
I used to think the db/schema.rb in a Rails project stored the database schema,
A recent question contains a problem that I many times used to think about
I need a string->string mapping to be used at runtime (think NSDictionary ), except

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.