rick

rick

  • NA
  • 69
  • 0

dropdownlist selected item return wrong index

Nov 4 2019 2:58 PM

I have a WebForm application with a dropdownlist. The datasource for the  dropdown  is a DataTable with 4 item. The DataTable is built in codebehind.

DataTable rn = new DataTable();

rn.Columns.AddRange(new DataColumn[2]); 

rn.Columns.Add(new DataColumn("command", typeof(string)));

rn.Columns.Add(new DataColumn("url", typeof(string)));

DataRow dr;

dr = rn.NewRow();

dr["command"] = "Update Page";

dr["url"] = "~/MX/MXEntities.aspx";

rn.Rows.Add(dr);       3 more just like this

Each item has 2 columns. The dropdown displays correctly however when selecting the first or second item,  index of  0 is always returned. Items 3 or  4 always returns index  of 2.

string index = allTable.SelectedIndex.ToString();

string selectedvalue = allTable.SelectedItem.Value;

string selectedtext = allTable.SelectedItem.Text;

Got to be something really stupid but I sure can't see it. 
 

Answers (3)