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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:04:00+00:00 2026-06-01T12:04:00+00:00

I have a website for dance academy where Users can register and add/drop dance

  • 0

I have a website for dance academy where Users can register and add/drop dance classes.

In the web page to drop a particular dance, for a particular user, the dropdown displays her registered dances.

Now I want to delete one of the dances from the list. So I’ll remove the row from the table and also from the dropdownlist. The problem is that everytime the item with the lowest ID (index) is getting deleted, no matter which one the user selects. I think I am storing the DataTextField and DataValueField for the dropdown incorrectly. The code is:

private void PopulateDanceDropDown()
{       
        // Retrieve the username
        MembershipUser currentUser = Membership.GetUser();
        var username = currentUser.UserName;

        // Retrive the userid of the curren user
        var dancerIdFromDB = from d in context.DANCER
                             where d.UserName == username
                             select d.UserId;

        Guid dancerId = new Guid();
        var first = dancerIdFromDB.FirstOrDefault();
        if (first != null)
        {
            dancerId = first;
        }

        dances.DataSource = (from dd in context.DANCER_AND_DANCE
                                    where dd.UserId == dancerId
                                    select new
                                    {
                                        Text = dd.DanceName,
                                         Value = dd.DanceId
                                    }).ToList();

        dances.DataTextField = "Text";
        dances.DataValueField = "Value";
        dances.DataBind();
    }

    protected void dropthedance(object o, EventArgs e)
    {
        String strDataValueField = dances.SelectedItem.Value;
        int danceIDFromDropDown = Convert.ToInt32(strDataValueField);
        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 problem is in the line:

String strDataValueField = dances.SelectedItem.Value;

The strDataValueField is always getting the minimum id from the list of dance item ids in the dropdown (which happens by default). I want this to hold the id of the dance selected by the user.

  • 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-01T12:04:01+00:00Added an answer on June 1, 2026 at 12:04 pm

    I would ensure the dropdownlist items are generated only if there is no postback – if (!IsPostback).

    Also I would check the viewstate to ensure it is enabled. If you are disabling the viewstate and then rebinding the control on postback, it might be losing the selected item.

    I would also try setting the dropdownlist to autopostback and attach a selected index changed event to see if the changes are at least being sent that way.

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

Sidebar

Related Questions

I have website where users can login with their Facebook account. I am using
i have website of application which sells applications online.on the home page i want
So basically I have website that has names of cities that can be checked
I have a website that plays mp3s in a flash player. If a user
I have website with like button and facebook page that was created manually. I
i am calling iframe on html page within it i have website url, i
I have a website where you can search on stuff with dates and more.
What if I have website with a button. User clicks on the button and
I have a website where users submit questions (zero, one or multiple per day),
I have website written in Rails. I constantly find myself tweaking page titles, intro

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.