Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring records in a dropdownlist from DB without using LINQ Data source
    text
    copied!<p>I have a website for dance academy where Users can register and add/drop dance classes.</p> <p>In the web page to drop a particular dance, for a particular user, the dropdown displays her registered dances. </p> <p>Now I want to delete one of the dances from the list. </p> <p>So i'll remove the row from the table and also from the dropdownlist. The problem is that every time the item with the lowest ID (index) is getting deleted, no matter which one the user selects.</p> <p>I think I am storing the DataTextField and DataValueField for the dropdown incorrectly. Can someone please help me out? The code is:</p> <pre><code>private void PopulateDanceDropDown() { var registereddanceList = from dd in context.DANCER_AND_DANCE where dd.UserId == dancerId select new { Text = dd.DanceName, Value = dd.DanceId }; dances.DataSource = registereddanceList; 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); } PopulateDanceDropDown(); } &lt;asp:DropDownList ID = "dances" runat="server"&gt; &lt;/asp:DropDownList&gt; &lt;asp:Button ID="dropDance" runat="server" OnClick="dropthedance" Text="Drop Class" BackColor="Maroon" ForeColor="#FFCC99"/&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload