ComboBox don't resolve the DisplayField in the ComboBox.Text

  1. #1

    ComboBox don't resolve the DisplayField in the ComboBox.Text

    Hi Support-Team,

    i have one Problem with the ComboBox. I initial the Properties DisplayField and ValueField. If i select a Item in the List, i will not see the DisplayField - Text in the ComboBox.Text. I see the ValueField - Property in the ComboBox.Text.

    <ext:ComboBox ID="ComboBox1" runat="server"  FieldLabel="Rufnummer:" AllowBlank="false" 
             DisplayField="Miet_Obj_Bez" ValueField="ID_Stammdaten" 
             MinChars="1" QueryMode="Local" 
             TriggerAction="All"  SelectOnFocus="true" 
              ondirectchange="ComboBox1_DirectChange"  ondirectselect="ComboBox1_DirectSelect" 
             ValueNotFoundText="Kein Ergebnis gefunden">
             <ListConfig  LoadingText="Suche...">
                 <ItemTpl ID="ItemTpl1" runat="server">
                     <Html>
                         <div class="ComboBoxSearch-item">
                             <h3><span>{Miet_Obj_Bez}</span></h3>
    		     </div>
                     </Html>
                  </ItemTpl>
             </ListConfig>
             <Store>
                 <ext:Store ID="Store1" runat="server" AutoLoad="false" IDProperty="ID_Stammdaten">
                     <Model>
                         <ext:Model ID="Model1" runat="server">
                             <Fields>
                                 <ext:ModelField Name="ID_Stammdaten" Type="Int" />
                                 <ext:ModelField Name="Miet_Obj_Bez"/>
                             </Fields>
                         </ext:Model>                            
                     </Model>
                  </ext:Store>
             </Store>
    </ext:ComboBox>
    Last edited by KevinWinter; Feb 27, 2013 at 9:33 AM.
  2. #2
    Please post runable sample reproduces the issue
  3. #3
    I Make a Mini-Projekt with the same Effekt

    <%@ Page Title="Startseite" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
        <script>
        </script>
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:ComboBox 
            ID="ComboBox1" runat="server"  
            FieldLabel="Countries:" 
            DisplayField="Name" ValueField="ID" 
            MinChars="1" QueryMode="Local" 
            TriggerAction="All"  SelectOnFocus="true" 
            ondirectchange="ComboBox1_DirectChange"  ondirectselect="ComboBox1_DirectSelect" 
            ValueNotFoundText="no result">
            <ListConfig  LoadingText="searching...">
                <ItemTpl ID="ItemTpl1" runat="server">
                    <Html>
                       <h3><span>{Name}</span></h3>
                    </Html>
                </ItemTpl>
            </ListConfig>
            <Store>
                <ext:Store ID="Store1" runat="server" AutoLoad="true" IDProperty="ID">
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="Name"  Type="String" />
                                <ext:ModelField Name="ID" Type="Int" />
                            </Fields>
                        </ext:Model>                            
                    </Model>
                </ext:Store>
            </Store>
        </ext:ComboBox>
    </asp:Content>


    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    using DataAccessLayer;
    using DataAccessLayer.Mapper;
    using System.Data;
    
    using ListItem = Ext.Net.ListItem;
    
    public partial class _Default : System.Web.UI.Page
    {
        private static List<Countries> ComboBoxList = new List<Countries>();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store1.DataSource = Mac1ComboBoxHelper.GetAll();
                Store1.DataBind();
                ComboBox1.DataBind();
            }
        }
    
        protected void InitComboBox(string filter)
        {
            Store1.DataSource = Mac1ComboBoxHelper.GetFilter(filter);
            Store1.DataBind();
        }
    
        protected void ComboBox1_DirectChange(object sender, DirectEventArgs e)
        {
            InitComboBox(ComboBox1.Text);
        }
    
        protected void ComboBox1_DirectSelect(object sender, DirectEventArgs e)
        {
            ListItem current = ComboBox1.SelectedItem;
    
            if (current != null)
            {
                
    
                //string str = current.Text;
                //ComboBox1.Text = str;
                //ComboBox1.ValueField = "ID_Stammdaten";
    
                
            }
    
        }
    }
    
    public class Countries
    {
        public int ID { get; set; }
        public string Name { get; set; }
    
        public Countries()
        {
    
        }
        public Countries(int ID, string CountryName)
        {
            this.ID = ID;
            this.Name = CountryName;
        }
    }
    
    public class Mac1ComboBoxHelper
    {
        private static List<Countries> ComboBoxList = new List<Countries>();
    
        public static List<Countries> GetAll()
        {
            List<Countries> list = new List<Countries>();
    
            Countries country1 = new Countries(1, "Russia");
            Countries country2 = new Countries(2, "Sweden");
            Countries country3 = new Countries(3, "Germany");
            Countries country4 = new Countries(4, "Turkey");
            Countries country5 = new Countries(1, "France");
            Countries country6 = new Countries(2, "China");
            Countries country7 = new Countries(3, "USA");
            Countries country8 = new Countries(4, "Switzerland");
    
            list.Add(country1);
            list.Add(country2);
            list.Add(country3);
            list.Add(country4);
            list.Add(country5);
            list.Add(country6);
            list.Add(country7);
            list.Add(country8);
    
            return list;
        }
    
    
        /// <summary>
        /// Is for the Filtering
        /// </summary>
        /// <param name="Filter"></param>
        /// <returns></returns>
        public static List<Countries> GetFilter(string Filter)
        {
            List<Countries> temptList = new List<Countries>();
    
            foreach (Countries record in ComboBoxList)
            {
                temptList.Add(record);
            }
    
            if (!string.IsNullOrEmpty(Filter) && Filter != "*")
            {
                temptList.RemoveAll(combo => !combo.Name.ToLower().StartsWith(Filter.ToLower()));
            }
            else
            {
                temptList.Clear();
                temptList = GetAll();
            }
    
            var resultList = from c in temptList
                             orderby c.Name
                             select c;
    
            return resultList.ToList<Countries>();
        }
    
    
    }
  4. #4
    The get All have a Bug in the Mini Projekt....but the Effect in the ComboBox is the same.

    public static List<Countries> GetAll()
    {
    ComboBoxList.Clear();

    Countries country1 = new Countries(1, "Russia");
    Countries country2 = new Countries(2, "Sweden");
    Countries country3 = new Countries(3, "Germany");
    Countries country4 = new Countries(4, "Turkey");
    Countries country5 = new Countries(1, "France");
    Countries country6 = new Countries(2, "China");
    Countries country7 = new Countries(3, "USA");
    Countries country8 = new Countries(4, "Switzerland");

    ComboBoxList.Add(country1);
    ComboBoxList.Add(country2);
    ComboBoxList.Add(country3);
    ComboBoxList.Add(country4);
    ComboBoxList.Add(country5);
    ComboBoxList.Add(country6);
    ComboBoxList.Add(country7);
    ComboBoxList.Add(country8);

    return ComboBoxList;
    }
  5. #5
    I Select one Country and my Debugger show me in the DirectChange - Method this Value:
    ComboBox.Text = 2?! The Value is the ValueField, and not the DisplayField.



    protected void ComboBox1_DirectChange(object sender, DirectEventArgs e)
    {
    InitComboBox(ComboBox1.Text);
    }
  6. #6
    You rebind store after in combobox change event, new data in the store has no record with selected value therefore text is not displayed
    What a sense rebind the store on each combo change?
  7. #7
    Okey the reason behind the rebinding ist a filtered list.

    I can select a item from the Combox-List or i writte one Letter in the Textbox and i get the filted list.

    I need for this a rebind
  8. #8
    Okey i try the same Sample without the Rebinding. But in the ComboBox1_DirectChange is the same problem.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    using System.Data;
    
    using ListItem = Ext.Net.ListItem;
    
    public partial class _Default : System.Web.UI.Page
    {
        private static List<Countries> ComboBoxList = new List<Countries>();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store1.DataSource = Mac1ComboBoxHelper.GetAll();
                Store1.DataBind();
                ComboBox1.DataBind();
            }
        }
    
        protected void InitComboBox(string filter)
        {
            //Store1.DataSource = Mac1ComboBoxHelper.GetFilter(filter);
            //Store1.DataBind();
        }
    
        protected void ComboBox1_DirectChange(object sender, DirectEventArgs e)
        {//The Brakepoint sad the ComboBox1.Text is 1..2...3 or other id. 
    
            string result = ComboBox1.Text;
            //InitComboBox(ComboBox1.Text);
        }
    
        protected void ComboBox1_DirectSelect(object sender, DirectEventArgs e)
        {
            //ListItem current = ComboBox1.SelectedItem;
    
            //if (current != null)
            //{
                
    
            //    //string str = current.Text;
            //    //ComboBox1.Text = str;
            //    //ComboBox1.ValueField = "ID_Stammdaten";
    
                
            //}
    
        }
    }

Similar Threads

  1. [CLOSED] Combobox DisplayField Template
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 01, 2013, 9:24 AM
  2. Get value of DisplayField of Combobox
    By littletran in forum 1.x Help
    Replies: 0
    Last Post: May 17, 2012, 7:32 AM
  3. Combobox DisplayField 2 fields???
    By 78fede78 in forum 1.x Help
    Replies: 3
    Last Post: Sep 06, 2010, 2:07 PM
  4. Replies: 3
    Last Post: Mar 30, 2010, 3:03 AM
  5. DisplayField of the ComboBox
    By Maia in forum 1.x Help
    Replies: 2
    Last Post: Jun 04, 2009, 10:46 AM

Posting Permissions