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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:55:58+00:00 2026-06-01T14:55:58+00:00

I have a dropdown in my webpage, which always returns the value 0 as

  • 0

I have a dropdown in my webpage, which always returns the value 0 as the selected index no matter whichever item the user selects. I have populated the dropdown using a DB query. And I am populating in on Page_Load method in my page. The code shown below does the specified work: int danceid;

    protected void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDanceDropDown();
        }

    }    

    private void PopulateDanceDropDown()
    {         
        DataTable dt = new DataTable();DataRow row = null;
        dt.Columns.Add("Did", Type.GetType("System.Int32"));
        dt.Columns.Add("DName", Type.GetType("System.String"));    
        var dancer_dance = (from dd in context.DANCER_AND_DANCE
                       where dd.UserId == dancerId
                       select new
                       {
                           Value = dd.DanceId,
                           Text = dd.DanceName

                       }).ToList();    

        foreach (var dndd in dancer_dance)
        {        
            row = dt.NewRow();
            row["Did"] = dndd.Value;
            row["DName"] = dndd.Text;
            dt.Rows.Add(row);    dances.DataSource = dt;    
            dances.DataTextField = dt.Columns[1].ToString();
        if (!IsPostBack)
        {
            dances.DataBind();
        }

    }    
    protected void changeIndex(object o, EventArgs e)
    {
        danceid = dances.SelectedIndex;
    }
    protected void dropthedance(object o, EventArgs e)
    {
        int danceIDFromDropDown = danceid;
        var dancer_dance = from dd in context.DANCER_AND_DANCE
                           where dd.DanceId == danceIDFromDropDown
                           select dd;
        foreach (var dndd in dancer_dance)
        {
             context.DANCER_AND_DANCE.DeleteOnSubmit(dndd);

        }
        try
        {
            context.SubmitChanges();
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
  }

The line int danceIDFromDropDown = danceid; in the method dropthedance always has the value 0. Pleaseeeeeeeeeeeeee help someone

  • 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-01T14:55:59+00:00Added an answer on June 1, 2026 at 2:55 pm

    Are you sure that you want to be using the index as the ID? Typically, you’re going to want to set the actual ID from your database as the DataValueField and then you can grab the value that way.

    But I also noticed that you grab the index and place it into a variable on the indexchanged event and then you try to use that value in a different method. I’m assuming that danceid is an attribute somewhere not shown here. At any rate, the value isn’t persisting through postbacks. Instead of trying to store it in a variable like you would on a desktop application, try adding EnableViewState=”True” to your dropdown control. Then get that index on your submit handler directly. Or if you really want to store it in a variable, then try persisting the value of that variable by storing it in the session or caching it, then pull from that cache/session variable when it comes time to actually use the value.

    But again, it might be better practice to place the danceid in the listitem object itself. Just the though of basing IDs on item indexes makes me shudder, especially when you populating the list from a database, because what happens when you add a new item to that list in the library and then try to sort them by name… then your indices become useless.

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

Sidebar

Related Questions

I have dropdown menu..which is dynamic.. How can get value of the last item
i have a select dropdown on a webpage: <select class=designs id=color name=Color> <option value=>Select
Here's the situation I have a webpage which has one drop down called prefer.
I have a one dropdown box in webpage that is with autopostback = true
I have a webpage written in HTML. I have a dropdown list that is
I have a webpage built with a dropdown that has a list of books.
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have an ASP.NET 4 webpage that contains an update panel which just allows
i have an asp.net-mvc webpage and i want to show a dropdown list that
In my webpage I have two dropdown controls for namely ddlmonth and ddldays (

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.