Note that there are some explanatory texts on larger screens.

plurals
  1. POFor a dropdownlist, SelectedIndex always returns the value 0
    primarykey
    data
    text
    <p>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;</p> <pre><code> 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); } } </code></pre> <p>The line int danceIDFromDropDown = danceid; in the method dropthedance always has the value 0. Pleaseeeeeeeeeeeeee help someone </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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