How to choose a predefined dropdownlist option in a popup before showing from code

This line sets the selected index to the correct number:

ddlCliNewMsg.SelectedIndex = ddlCliNewMsg.Items.IndexOf(ddlCliNewMsg.Items.FindByValue(dr["ClientText"].ToString())); 

But when the popup loads, the index 0 is selected.

+1
javascript jquery c #
Mar 05 '15 at 16:58
source share
2 answers

Change

  if (dr["ClientText"].ToString().Length > 0) { ddlCliNewMsg.SelectedValue = dr["ClientText"].ToString(); } 

For

  if (dr["ClientText"].ToString().Length > 0) { ddlCliNewMsg.ClearSelection(); //making sure the previous selection has been cleared ddlCliNewMsg.Items.FindByValue(dr["ClientText"].ToString()).Selected = true; } 
+2
Mar 06 '15 at 7:36
source share
  for populating dropdownlist use below code: ddlCliNewMsg.DataSource = dataSource; ddlCliNewMsg.DataTextField = textField; ddlCliNewMsg.DataValueField = valueField; ddlCliNewMsg.DataBind(); textField and valueField is data field for text and value of dropdownlist. for selecting item with your value use below code: ddlCliNewMsg.Items.FindByValue("your value").Selected = true; replace your value with "your value" 
0
Mar 05 '15 at 17:14
source share



All Articles