[CLOSED] Custom ComboBox loading

  1. #1

    [CLOSED] Custom ComboBox loading

    Hi,

    I have one custom comboBox and I added inside one Store control and my purpose is that I will give one ID and ComboBox will be loaded automaticly by Store control. And when I need to refresh data inside store, I should be able to refresh comboBox or store control in ComboBox. How can I achieve this?

    This is my sample code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Ext.Net;
    using System.Data;
    
    namespace ExtWebControlLib
    {
        public class ComboBox : Ext.Net.ComboBox
        {
            private Store _store=null;
            protected Store InnerStore
            {
                get { return _store; }
                set { _store = value; }
            }
    
            private int _langID = 1;
            public int LangID
            {
                get { return _langID; }
                set { _langID = value; }
            }
    
            private DataTable GetRootObjects()
            {
                DataTable retValue = null;
                try
                {
                    int langID = LangID;
                    retValue = SysMgmWeb_Methods.fn_RootObjects(langID);
                }
                catch (Exception ex)
                {
                    //Response.Write(ex.Message);
                }
                return retValue;
            }
    
            private void LoadStore()
            {
                DataTable dtRootObjects = GetRootObjects();
    
                this.InnerStore.DataSource = dtRootObjects;
                this.InnerStore.DataBind();
            }
    
            void Store_RefreshData(object sender, StoreRefreshDataEventArgs e)
            {
                LoadStore();
            }
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                InnerStore = new Store();
                InnerStore.AutoLoad = true;
                InnerStore.AutoDataBind = true;
                JsonReader jr = new JsonReader();
                jr.IDProperty = "ObjID";
                jr.Fields.Add(new RecordField("ObjID"));
                jr.Fields.Add(new RecordField("ObjName"));
                jr.Fields.Add(new RecordField("ObjType"));
                InnerStore.Reader.Add(jr);
                InnerStore.RefreshData += new Ext.Net.Store.AjaxRefreshDataEventHandler(Store_RefreshData);
                this.Store.Add(InnerStore);
                this.ValueField = "ObjID";
                this.DisplayField = "ObjName";
            }
        }
    }
    Last edited by Daniil; Mar 24, 2011 at 10:23 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Not sure that I understand you properly, but I can tell the following.

    "object sender" in Refresh handler is a Store instance. So, you could use something like this:

    Example
    protected void Store_RefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        Store store = sender as Store;
        store.DataSource = someData;
        store.DataBind();
    }
  3. #3
    Hi,

    As you see in my code, I have one custom control derived from combobox. And my purpose is that this control will have one ID property which will be used in a database. When I set this property combobox will be loaded automatically. To achieve this, I added one store control in custom control. But, when I use this control in a page, combobox isn't loaded
  4. #4
    I would suggest you the following configuration (actually, it's your a little bit modified example).

    ComboBox.cs
    using System;
    using System.Collections.Generic;
    
    using Ext.Net;
    
    namespace Work
    {
    
        public class ComboBox : Ext.Net.ComboBox
        {
            private Store _store = null;
            protected Store InnerStore
            {
                get { return _store; }
                set { _store = value; }
            }
    
            private int _langID = 1;
            public int LangID
            {
                get { return _langID; }
                set 
                { 
                    _langID = value;
                    this.LoadStore();
                }
            }
    
            private List<object> GetRootObjects()
            {
                List<object> retValue = new List<object>();
    
                for (int i = 0; i < 3; i++)
                {
                    retValue.Add(new
                    {
                        ObjID = this.LangID + "_ObjID" + i,
                        ObjName = this.LangID + "_ObjName" + i
                    });
                }
                return retValue;
            }
    
            private void LoadStore()
            {
                List<object> dtRootObjects = GetRootObjects();
    
                this.InnerStore.DataSource = dtRootObjects;
                this.InnerStore.DataBind();
            }
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                InnerStore = new Store();
                JsonReader jr = new JsonReader();
                jr.IDProperty = "ObjID";
                jr.Fields.Add(new RecordField("ObjID"));
                jr.Fields.Add(new RecordField("ObjName"));
                jr.Fields.Add(new RecordField("ObjType"));
                InnerStore.Reader.Add(jr);
                this.Store.Add(InnerStore);
                this.ValueField = "ObjID";
                this.DisplayField = "ObjName";
    
                if (!Ext.Net.X.IsAjaxRequest)
                {
                    this.LoadStore();
                }
            }
        }
    }
    Example .aspx Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {
            var combo = new Work.ComboBox()
            {
                ID = "ComboBox1"
            };
            this.Form.Controls.Add(combo);
        }
    
        protected void ChangeLangID(object sender, DirectEventArgs e)
        {
            var combo = (this.FindControl("ComboBox1") as Work.ComboBox);
            combo.LangID = 2;
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Change LangID" OnDirectClick="ChangeLangID" />
        </form>
    </body>
    </html>
  5. #5
    Thank you very much. It works now.

Similar Threads

  1. Replies: 4
    Last Post: Nov 03, 2011, 6:46 PM
  2. [CLOSED] Custom value in combobox
    By bakardi in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 28, 2011, 2:14 PM
  3. [CLOSED] Custom Search Combobox
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 04, 2010, 7:29 PM
  4. [CLOSED] custom search get value of combobox
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 05, 2009, 5:25 PM
  5. [CLOSED] Combobox not loading data
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 22, 2009, 6:45 AM

Tags for this Thread

Posting Permissions