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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:24:43+00:00 2026-05-26T20:24:43+00:00

I am using MS VS 2010, and working on an ASP.NET C# website. I

  • 0

I am using MS VS 2010, and working on an ASP.NET C# website. I am stuck on something that I think may be quite simple, maybe not though.

Lets say I have a drop down list.

DropDownList ddl = new DropDownList();
ddl.ID = "d355";
dynamicPanel.Controls.Add(ddl);

ListItem lstItem1 = new ListItem();
lstItem1.Text = "1";
ListItem lstItem2 = new ListItem();
lstItem2.Text = "2";

ddl.Items.Add(lstItem1);
ddl.Items.Add(lstItem2);
ddl.SelectedIndexChanged += new EventHandler(this.ddl_SelectedIndexChanged);

Since we programatically created our drop down list, we need to also create our custom event handler that we tied to it.

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    // add the selected index to a counter
    counter +=((DropDownList)sender).SelectedIndex;
    // Now this is where I get stuck, if the current selected index is less
    // than the previous selected index, I want to subtract from the counter



}

This is where my problem lies. Please read the comments in the event handler. (Sorry if I have some of the syntax off, this is all free hand at the moment)

I have a feeling that I can get the previous selected index (or item it doesn’t matter) from the event args ((DropDownList)e).?

Please help >.< This doesn’t seem too bad!

  • 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-26T20:24:44+00:00Added an answer on May 26, 2026 at 8:24 pm

    I don’t think that there is a built in mechanism, but you could use ViewState or a HiddenField to keep the previous index.
    Something like the following:

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = ((DropDownList)sender).SelectedIndex;
            if (selectedIndex < (int)ViewState["PreviousIndex"])
            {
                counter -= ((DropDownList)sender).SelectedIndex;
            }
            else
            {
                counter += ((DropDownList)sender).SelectedIndex;
            }
            // update the index
            ViewState["PreviousIndex"] = selectedIndex;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.net MVC2 website that was working great when using Visual Studio
Currently I'm working on a reporting website in VS 2010 using ASP.Net 4.0 and
I'm working on a new blog website created using ASP.NET MVC. I'm wondering what
I'm working on an ASP.NET webforms app that will serve as a simple intake
I have been working in Visual Studio 2010, in asp.net, i am using Jquery
Using VS 2010, with ASP.NET, and .NET 3.0, and C#... When I use a
I recently joined a team that is working on a ASP.NET MVC project.. they
ASP.NET 4.0: My laptop is running 64-bit Win7 Ultimate, using VS 2010 and IIS7.
I am working on an ASP.NET project in Visual Studio .NET 2010 and attempting
I am trying to set up a mono asp.net 4.0 test website that uses

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.