Results 1 to 8 of 8

Thread: Add Items to combobox dynamically problem

  1. #1
    Member
    Join Date
    Apr 2009
    Location
    Posts
    36

    Add Items to combobox dynamically problem



    Hi,

    I have a next problem..
    I want to fill the combobox with items.. but I can do this only in page load... I need fill new items when AjaxEvent happen..
    I prepare little example of my problem.

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test_combobox.aspx.vb" Inherits="test_combobox" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    
    <!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>Untitled Page</title>
    </head>
    <body>
    テつ*   <form id="form1" runat="server">
    テつ*   
    テつ*       <ext:ScriptManager ID="ScriptManager1" runat="server" />
    テつ*   
    
    テつ*   <ext:Panel ID="Panel1" runat="server" Height="300" Title="Title">
    テつ*       <Body>
    テつ*           <ext:ComboBox ID="ComboBox1" runat="server">
    テつ*           </ext:ComboBox>
    テつ*           <ext:Button ID="Button1" runat="server" Text="Submit">
    テつ*           <AjaxEvents>
    テつ*           <Click OnEvent="mmks_fillcombobox">
    テつ*           </Click>
    テつ*           </AjaxEvents>
    テつ*           </ext:Button>
    テつ*          テつ*
    テつ*       </Body>
    テつ*   </ext:Panel>
    テつ*   </form>
    </body>
    </html>
    and simple method to refill combo isテつ*

    Code:
    Partial Class test_combobox
    テつ*   Inherits System.Web.UI.Page
    
    テつ*   Protected Sub mmks_fillcombobox()
    テつ*       Dim lni As Integer
    テつ*       For lni = 1 To 10
    テつ*           Me.ComboBox1.Items.Add(New Coolite.Ext.Web.ListItem("Page " + lni.ToString, lni.ToString))
    テつ*       Next
    テつ*   End Sub
    End Class
    When I try to expand combobox - I'v got a JavaScript error..

    Microsoft JScript runtime error "This.store" is null or not an objectテつ*



    I look examples.. and everywhere using Store object.. can I avoid to use store object and fill items with Items.add() in the code?

    Thank you!

  2. #2
    Member
    Join Date
    Apr 2009
    Location
    Posts
    36

    RE: Add Items to combobox dynamically problem



    Hi,

    I understand about - no ways to add during AjaxEvent items to the combobox. I try to use Store as it shows on example.. and I have NO SUCCESS...

    In the example we have a code

    Code:
    テつ*          List<object> data = new List<object>();
    
    テつ*           foreach (XmlNode cityNode in xmlDoc.SelectNodes(string.Concat("countries/country[@code='", this.Countries.SelectedItem.Value, "']/city")))
    テつ*           {
    テつ*               string id = cityNode.SelectSingleNode("id").InnerText;
    テつ*               string name = cityNode.SelectSingleNode("name").InnerText;
    
    テつ*               data.Add(new{Id=id, Name = name});
    テつ*           }
    テつ*

    There we can see - we add one "Anonymous type" to the List collection.. I try to do same using VB.NET and I have not success.. the items are here.. but all empty

    Code:
    テつ*       Dim loObjects As List(Of Object) = New List(Of Object)
    テつ*       loObjects.Add(New With {.id = "1", .name = "test"})
    
    テつ*       Me.Store1.DataSource = loObjects
    テつ*       Me.Store1.DataBind()


    So far as I seen.. in Debuger Watch window - the Anonymous type for C# and VB.NET is not a SAME.. so VB has a middle layer.. with "anonymous type" object.. and C# has properties id and name directy for item.

    So.. I second day try to solve this problem and have not success with Store ..

    Please Help!


  3. #3
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,255

    RE: Add Items to combobox dynamically problem

    Hi,

    What problems do you have? Can you show your code?
    You need use store to rebind combo data during AjaxEvent.
    For example add OnRefreshData handler for Store and on client side call

    js code
    Code:
    Store1.reload();
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  4. #4
    Member
    Join Date
    Apr 2009
    Location
    Posts
    36

    RE: Add Items to combobox dynamically problem



    Hi Vlad,

    Thanks for response.. here is a code...テつ*

    The task background was.. When I select record in DataGrid.. then AjaxEvent executed.. then I need update a combobox..

    (I get xml from SQL Database.. by Id and then Fill combobox with items from this xml)テつ*

    Here just an example. what I want to do...テつ*

    Thank you very much for your answers!

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test_combobox.aspx.vb" Inherits="test_combobox" %>
    
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    
    <!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>Untitled Page</title>
    </head>
    <body>
    テつ*   <form id="form1" runat="server">
    テつ*   
    テつ*       <ext:ScriptManager ID="ScriptManager1" runat="server" />
    テつ*   
    
    テつ*   <asp:XmlDataSource ID="XmlDataSource1" runat="server">
    テつ*       <Data>
    テつ*           <row>
    テつ*               <id>1</id>
    テつ*               <name>Page 1</name>
    テつ*           </row>
    テつ*       </Data>
    テつ*   </asp:XmlDataSource>
    テつ*   <ext:Store runat="server" ID="Store1" AutoLoad="false">
    テつ*       <AjaxEventConfig>
    テつ*           <EventMask ShowMask="false" />
    テつ*       </AjaxEventConfig>
    テつ*       <Reader>
    テつ*           <ext:JsonReader ReaderID="id" >
    テつ*               <Fields>
    テつ*                   <ext:RecordField Name="id" Type="String"  />
    テつ*                   <ext:RecordField Name="name" Type="String" />
    テつ*               </Fields>
    テつ*           </ext:JsonReader>
    テつ*       </Reader>
    テつ*   </ext:Store>  テつ*
    テつ*   <ext:Panel ID="Panel1" runat="server" Height="300" Title="Title">
    テつ*       <Body>
    テつ*           <ext:ComboBox ID="ComboBox1" runat="server" StoreID="Store1"
    テつ*           TypeAhead="true" 
    テつ*           Mode="Local"
    テつ*           ForceSelection="true" 
    テつ*           TriggerAction="All" 
    テつ*           DisplayField="name" 
    テつ*           ValueField="id"
    テつ*           EmptyText="Loading..." 
    テつ*           ValueNotFoundText="Loading...">
    テつ*           </ext:ComboBox>
    テつ*           <ext:Button ID="Button1" runat="server" Text="Submit">
    テつ*           <AjaxEvents>
    テつ*           <Click OnEvent="mmks_fillcombobox">
    テつ*           </Click>
    テつ*           </AjaxEvents>
    テつ*           </ext:Button>
    テつ*          テつ*
    テつ*          テつ*
    テつ*          テつ*
    テつ*       </Body>
    テつ*   </ext:Panel>
    テつ*   </form>
    </body>
    </html>


    Code:
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Data
    
    
    Partial Class test_combobox
    テつ*   Inherits System.Web.UI.Page
    
    テつ*   Protected Sub mmks_fillcombobox()
    テつ*       Dim loObjects As List(Of Object) = New List(Of Object)
    テつ*       loObjects.Add(New With {.id = "1", .name = "test"})
    テつ*       Me.Store1.DataSource = loObjects
    テつ*       Me.Store1.DataBind()
    テつ*   End Sub
    End Class
    テつ*

  5. #5
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,255

    RE: Add Items to combobox dynamically problem

    Hi,

    I think you need to define correct handler signature. You need to add two arguments to the AjaxEvent handler

    Code:
    (sender As Object, e As Coolite.Ext.Web.AjaxEventArgs)
    
    The must have the same signature as delegate
    Delegate Sub AjaxEventHandler(sender As Object, e As Coolite.Ext.Web.AjaxEventArgs)
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  6. #6
    Member
    Join Date
    Apr 2009
    Location
    Posts
    36

    RE: Add Items to combobox dynamically problem



    Hi Vlad!

    Thank you for solution.. you are right.. now the combobox filled with items.

    But new problem appears .. Now I can't set the default value for combobox in this method..



    Code:
    テつ*       Dim loObjects As List(Of Object) = New List(Of Object)
    テつ*       loObjects.Add(New With {.id = "1", .name = "test"})
    
    テつ*       Me.Store1.DataSource = loObjects
    テつ*       Me.Store1.DataBind()
    テつ* Me.cboPages.SetValue("1")


    And the value still empty.. why? What do I wrong?

    テつ*

  7. #7
    Ext.NET - Dev Team Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Russia
    Posts
    15,255

    RE: Add Items to combobox dynamically problem

    Hi,

    SetValue method using during AjaxEvent only. In your case need useテつ*SelectedItemテつ*property
    Code:
    ComboBox1.SelectedItem.Value = "1";
    テつ*
    Vladimir Shcheglov
    Ext.NET, Inc.
    Development Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  8. #8
    Member
    Join Date
    Apr 2009
    Location
    Posts
    36

    RE: Add Items to combobox dynamically problem

    Thank you for the best support!テつ*

Similar Threads

  1. [CLOSED] Problem selecting items in Combobox
    By tlfdesarrollo in forum 1.x Premium Help
    Replies: 3
    Last Post: Jan 17, 2012, 6:57 PM
  2. Add items to menu dynamically
    By sunshine in forum 1.x Help
    Replies: 5
    Last Post: Mar 10, 2011, 6:44 PM
  3. Problem about change ComboBox's store dynamically
    By zhangsir199 in forum 1.x Help
    Replies: 0
    Last Post: Aug 04, 2010, 2:46 AM
  4. Replies: 3
    Last Post: Jul 24, 2010, 4:31 PM
  5. Replies: 1
    Last Post: Apr 15, 2010, 8:07 PM

Posting Permissions