EXT.NET 3.1 RELEASED! With Tablet Support!
We have been working hard and are happy to announce the release of Ext.NET 3.1. Click here for a full list of changes and make sure you visit our download page now to get the latest version.
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.

    
    <%@ 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Â*

    
    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

    
    Â*          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

    
    Â*       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
    Object.NET + Ext.NET Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Saint-Petersburg, Russia
    Posts
    15,420

    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
    Store1.reload();
    Vladimir Shcheglov
    Sr. Developer

  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!

    
    <%@ 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>


    
    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
    Object.NET + Ext.NET Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Saint-Petersburg, Russia
    Posts
    15,420

    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

    (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
    Sr. Developer

  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..



    
    Â*       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
    Object.NET + Ext.NET Vladimir's Avatar
    Join Date
    Mar 2008
    Location
    Saint-Petersburg, Russia
    Posts
    15,420

    RE: Add Items to combobox dynamically problem

    Hi,

    SetValue method using during AjaxEvent only. In your case need useÂ*SelectedItemÂ*property
    ComboBox1.SelectedItem.Value = "1";
    Â*
    Vladimir Shcheglov
    Sr. Developer

  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, 7:57 PM
  2. Add items to menu dynamically
    By sunshine in forum 1.x Help
    Replies: 5
    Last Post: Mar 10, 2011, 7:44 PM
  3. Problem about change ComboBox's store dynamically
    By zhangsir199 in forum 1.x Help
    Replies: 0
    Last Post: Aug 04, 2010, 3:46 AM
  4. Replies: 3
    Last Post: Jul 24, 2010, 5:31 PM
  5. Replies: 1
    Last Post: Apr 15, 2010, 9:07 PM

Posting Permissions