Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understood you right, you only need to change the value displayed in <code>dropDownListCity</code> according to the value selected in <code>dropDownListPostal</code>. To do so, you need to bind both dropdown lists in <code>Page_Load</code> and then handle the selected index when <code>SelectedIndexChanged</code> is triggered.</p> <pre><code>private IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; GetData() { using(var dataContext = new DbEntities()) { return dataContext.VW_CustumAddress .ToList() .Select(item =&gt; new KeyValuePair&lt;string, string&gt;(item.Postal, item.City)) .ToArray(); } } protected void Page_Load(object sender, EventArgs e) { if(!IsPostback) { IEnumerable&lt;KeyValuePair&lt;string,string&gt;&gt; data = GetData(); //Bind Postal dropdown list dropDownListPostal.DataSource = data.Select(kvp =&gt; kvp.Key).ToList(); // ^ Select only 'Postal' column in dropdown list. dropDownListPostal.DataBind(); // Bind City dropdown list // We need to bind to a key-value pair to know the correspondence between items dropDownListCity.DataValueField = "Key"; dropDownListCity.DataTextField = "Value"; dropDownListCity.DataSource = data; dropDownListCity.DataBind(); } } </code></pre> <p>Now, after you bound your controls to data you only need to handle <code>SelectedIndexChanged</code> event of <code>dropDownListPostal</code> (don't forget to set <code>AutoPostback="true"</code> in the markup of <code>dropDownListPostal</code>). <strong>EDIT</strong>: Before selecting an item, clear the selection of your dropdown list to make sure only one item is selected.</p> <pre><code>protected void OnDropDownListPostalSelectedIndexChanged(object sender, EventArgs e) { dropDownListCity.ClearSelection(); var postal = dropDownListPostal.SelectedValue; var listItem = dropDownListCity.Items.FindByValue(postal); listItem.Selected = true; } </code></pre> <p>That should do it. Hope it helps.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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