Assigning dynamic store to a dynamic combobox.

Page 1 of 2 12 LastLast
  1. #1

    Assigning dynamic store to a dynamic combobox.

    I can create a store and a combobox on the codebehind. I am just not sure how I assign this store to the combobox.

    //Add Subject Combobox
                ComboBox comboSubject = new ComboBox();
                comboSubject.FieldLabel = "Subject";
                // it would accept xStore to comboSubject.Store (Cannot implicitly convert type 'Ext.Net.Store' to 'Ext.Net.StoreCollection')
                comboSubject.Store = xStore();
                comboSubject.ValueField = "SubjectCode";
                comboSubject.DisplayField = "Description";
                comboSubject.AnchorHorizontal = "95%";
                comboSubject.AddTo(subContainSubject);
    
    //Create a Store
        private Ext.Net.Store xStore()
        {
            //Get the data for the store
            SubjectBLL subjectBLL = new SubjectBLL();
            List<Subject> subjectList = new List<Subject>();
            subjectList = subjectBLL.getAllSubjects();
    
            //Create the store
            JsonReader _jsonReader = new JsonReader();
            Store xStore = new Store();
    
            _jsonReader.Fields.Add("Description");
            _jsonReader.Fields.Add("SubjectCode");
    
            xStore.Reader.Add(_jsonReader);
            xStore.DataSource = subjectList;
            xStore.DataBind();
            return xStore;
        }
    Not sure how I get this working.:confused:
  2. #2
    Hi,

    comboSubject.Store.Add(xStore());
    Vladimir Shcheglov
    Sr. Developer
  3. #3

    Works Perfect! Thank you.

    Works Perfect! Thank you.
  4. #4

    Syntax Error

    From firebug I can see that it is now pulling the data but it breaks giving a syntax error message. The same store and the combobox works fine when creating it on the front end. While doing it from the code-behind page, however, it breaks. Am I the store in a wrong way?



    This is the response text error I get from firebug that doesn't make much sense to me:

    "{script:\"Ext.net.ResourceMgr.load([{url:\\"/NewCourses/extnet/extnet-data-js/ext.axd?v=34580\\"}], function(){xContainer.setVisible(!false);Ext.net.R esourceMgr.destroyCmp(\\"id4504336d2c1c4958a7e7c4b 5916683c9\\");new Ext.form.TextField({id:\\"id4504336d2c1c4958a7e7c4 b5916683c9\\",xtype:\\"textfield\\",anchor:\\"95%\ \",labelSeparator:\\"?\\",fieldLabel:\\"Course Number\\",allowBlank:false});subContainNumber.addA ndDoLayout(id4504336d2c1c4958a7e7c4b5916683c9);Ext .net.ResourceMgr.destroyCmp(\\"idf765be1c9dab4b538 d24f1d0419dd2a4\\");new Ext.form.ComboBox({id:\\"idf765be1c9dab4b538d24f1d 0419dd2a4\\",xtype:\\"combo\\",anchor:\\"95%\\",fi eldLabel:\\"Subject\\",displayField:\\"Description \\",hiddenName:\\"idf765be1c9dab4b538d24f1d0419dd2 a4_Value\\",triggerAction:\\"all\\",valueField:\\" SubjectCode\\",store:this.idf763bbdda91c4d269fa496 d9c8e28037=new Ext.ux.data.PagingStore({proxyId:\\"idf763bbdda91c 4d269fa496d9c8e28037\\",autoLoad:true,reader:new Ext.data.JsonReader({fields:[{name:\\"Description\\"},{name:\\"SubjectCode\\"}]}),directEventConfig:{},proxy:new Ext.data.PagingMemoryProxy([{\\"SubjectCode\\":\\"AAS\\",\\"Description\\":\\" Asian American Studies\\"}], false)}),submitValue:true});subContainSubject.addA ndDoLayout(idf765be1c9dab4b538d24f1d0419dd2a4);.ca llbackRefreshHandler(response, {serviceResponse: {success:true,data:{data:[{\\"SubjectCode\\":\\"AAS\\",\\"Description\\":\\" Asian American Studies\\"}], total: 0}}}, , o.eventType, o.action, o.extraParams);});\"}"
     //xRender Textboxes according to the premanent crosslisting selection
        [DirectMethod]
        public void CrossListing_change(object sender, DirectEventArgs e)
        {
            if (ckPermanentCrossListing.Checked == true)
            {
                xContainer.Hidden = false;        
    
                // Add Course Number
                TextField txtCrossList = new TextField();
                txtCrossList.FieldLabel = "Course Number";
                txtCrossList.AllowBlank = false;
                txtCrossList.LabelSeparator = "?";
                txtCrossList.AnchorHorizontal = "95%";
                txtCrossList.AddTo(subContainNumber);
    
                //Add Subject DDL
                ComboBox comboSubject = new ComboBox();
                comboSubject.FieldLabel = "Subject";
                comboSubject.Store.Add(xStore());
                comboSubject.ValueField = "SubjectCode";
                comboSubject.DisplayField = "Description";
                comboSubject.AnchorHorizontal = "95%";
                comboSubject.AddTo(subContainSubject);
    
                //Add Radio Button
            }
            else
            {
                xContainer.Visible = false;
            }
        }
    
        //Create a Store
        private Ext.Net.Store xStore()
        {
            //Get the data for the store
            SubjectBLL subjectBLL = new SubjectBLL();
            List<Subject> subjectList = new List<Subject>();
            subjectList = subjectBLL.getAllSubjects();
    
            //Create the store
            JsonReader _jsonReader = new JsonReader();
            Store xStore = new Store();
    
            _jsonReader.Fields.Add("Description");
            _jsonReader.Fields.Add("SubjectCode");
    
            xStore.Reader.Add(_jsonReader);
            xStore.DataSource = subjectList;
            xStore.DataBind();
            return xStore;
        }
  5. #5
    Hi,

    Please set ID for the Store
    Vladimir Shcheglov
    Sr. Developer
  6. #6

    Thank you again!

    Vladimir you are the man. you're awesome.

    All I was missing was an ID.

    Thank you.
  7. #7

    Dynamic Store and Combobox

    Hi Vladimir,

    I'm trying to fill combobox using dynamic store but unfortunately, I'm not being able to do it.
    Here is my code:

    Public Sub FillDropDown(ByRef DropDownID As ComboBox, ByVal DataDisplayField As String, ByVal DataValueField As String, ByVal strSQLQuery As String)
                    
            Dim dt As DataTable = SomeObject.GetDataTable(strSQLQuery)
    
            Dim cmbStore As New Ext.Net.Store
            cmbStore.ID = "comboStore"
    
            Dim jReader As New JsonReader()
            jReader.Fields.Add(DataDisplayField)
            jReader.Fields.Add(DataValueField)
    
            cmbStore.Reader.Add(jReader)
    
            cmbStore.DataSource = dt
            cmbStore.DataBind()
            'aspxPage.Controls.Add(cmbStore)
    
            DropDownID.StoreID = cmbStore.ID
            ''DropDownID.Store.Add(cmbStore)
            DropDownID.DisplayField = DataDisplayField
            DropDownID.ValueField = DataValueField
    
            DropDownID.DataBind()
            
        End Sub
    Please also note that I have this function in my project which is responsible to bind data for comboboxes on several .aspx pages and thus, I have passed Combobox with Ref parameter. I have also tried to pass an .aspx page with reference parameter to add store to the control collection of page but I did not work either (you can see the commented code). I have debugged this code and I'm getting value in my DataTable as well.

    What am I doing wrong here ??

    Thanks
    Last edited by Daniil; Dec 10, 2010 at 7:59 AM. Reason: Please use [CODE] tags
  8. #8
    Hi,

    At the future please wrap any code in [CODE ] tags, see
    http://forums.ext.net/showthread.php...ing-New-Topics

    Also it's better to start a new thread if the topic differs from this thread. If you assume that your question is related with some thread just post a link in an initial post of new thread.

    Regarding the question

    It needs to DataBind a Store, not a ComboBox.

    Example
    cmbStore.DataBind();
  9. #9
    Hi Daniil,

    Thanks for the quick response and other suggestions.
    but unfortunately, your suggestion did not work. I dont know there is something wrong on my side.
    I'm using Ext 1.0 version with ASP.NET framework 4.0
    This is the exception it throws when you run page
    "The Control 'cmbReportType' could not find the StoreID of 'comboStore'."

    I have attached sample page here.

    Thanks
    Attached Files
  10. #10
    Hi,

    There are two ways to get it working.

    First (store must be rendered before ComboBox it you used StoreID)
    page.Form.Controls.AddAt(0, cmbStore)
    DropDownID.StoreID = cmbStore.ID
    Second (store as a part of ComboBox but it must be added in Controls collection)
    'DropDownID.StoreID = cmbStore.ID 'remove this line
    DropDownID.Store.Add(cmbStore)
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: Apr 12, 2012, 6:44 AM
  2. Replies: 12
    Last Post: Sep 20, 2011, 3:33 PM
  3. Replies: 0
    Last Post: Mar 04, 2011, 1:05 PM
  4. Replies: 0
    Last Post: Mar 04, 2011, 7:46 AM
  5. Replies: 2
    Last Post: Jan 02, 2011, 4:06 PM

Tags for this Thread

Posting Permissions