[CLOSED] Could not refresh the combobox data in the UI after I added the new item?

  1. #1

    [CLOSED] Could not refresh the combobox data in the UI after I added the new item?

    My Code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="pa" runat="server">
            <TopBar>
                <ext:Toolbar ID="Tl1" runat="server">
                    <Items>
                        <ext:Button ID="b" runat="server" Text="OK">
                            <DirectEvents>
                                <Click OnEvent="AddItems">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:ComboBox SelectedIndex=0 ID="c1" runat="server">
                    <Items>
                        <ext:ListItem Text="0" Value="0" />
                        <ext:ListItem Text="1" Value="1" />
                    </Items>
                </ext:ComboBox>
            </Items>
        </ext:Panel>
        <div>
        </div>
        </form>
    </body>
    </html>
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void AddItems(object sender, DirectEventArgs e)
        {
            Ext.Net.ListItem l = new Ext.Net.ListItem();
            l.Text = "2";
            l.Value = "2";
            c1.Items.Add(l);
            X.Msg.Alert("",c1.Items.Count.ToString()).Show();
        }
    }
    My expection is that:
    After I click the "Button", the combobox items shoud be changed to
    1,2,3
    But the result is still
    1,2

    Please help me .

    Thanks.
    Last edited by Daniil; Oct 19, 2010 at 12:07 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Needs to re-render a ComboBox.
    Please use the Render() method.

    Example
    c1.Items.Add(l);
    c1.Render();
    As I can see it's your first post on the forum.
    You are welcome:)

    When you have a chance please rear this thread
    http://forums.ext.net/showthread.php...ing-New-Topics

    Please follow the recommendations which are described there.
    For example, wrap any code in [CODE ] tags.

    Here is an example demonstrating the best formatting of your example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void AddItems(object sender, DirectEventArgs e)
        {
            Ext.Net.ListItem l = new Ext.Net.ListItem();
            l.Text = "2";
            l.Value = "2";
            ComboBox1.Items.Add(l);
            X.Msg.Alert("", ComboBox1.Items.Count.ToString()).Show();
        }
    </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:Panel runat="server">
            <TopBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" Text="OK" OnDirectClick="AddItems" />
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:ComboBox ID="ComboBox1" runat="server" SelectedIndex="0">
                    <Items>
                        <ext:ListItem Text="0" Value="0" />
                        <ext:ListItem Text="1" Value="1" />
                    </Items>
                </ext:ComboBox>
            </Items>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Oct 18, 2010 at 9:12 AM.
  3. #3
    Hi,

    I don't think that rerender is best solution. Try the following code
    c1.GetStore().DataBind();
  4. #4
    Thank you all very much!

    It can work well.

    But when I try to generate all the controls in behind code (Refer to Daniil 's one Example), it show another error messge
    "Line: 15
    Error: 'ctl03' is undefined"

    Please help.


    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="PanelsCt" runat="server" AutoHeight="true" Title="Panels container">
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="Button1" runat="server" Text="Add">
                            <DirectEvents>
                                <Click OnEvent="AddNewPanel">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
    
    
                    </Items>
                </ext:Toolbar>
            </TopBar>
        </ext:Panel>
        </form>
    </body>
    </html>
    
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class Default5 : System.Web.UI.Page
    {
        public class PanelState
        {
            public string ID
            {
                get;
                set;
            }
            public string Title
            {
                get;
                set;
            }
        }
    
        private static List<PanelState> panels = new List<PanelState>();
        private static int pkID = 0;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RecreatePanels();
        }
    
        private void RecreatePanels()
        {
            foreach (PanelState panelState in panels)
            {
                CreatePanel(panelState);
            }
        }
    
        private Ext.Net.Panel CreatePanel(PanelState panelState)
        {
    
            var list1 = new ListItemCollection<Ext.Net.ListItem>
            {
                new Ext.Net.ListItem("AND","AND"),
                new Ext.Net.ListItem("OR","OR")
            };
    
            Ext.Net.ComboBox c1 = new Ext.Net.ComboBox
            {
                ID = panelState.ID + "_c1",
                Editable = false
            };
    
            c1.Items.AddRange(list1);
            c1.SelectedIndex = 0;
    
            var list2 = new ListItemCollection<Ext.Net.ListItem>
            {
                new Ext.Net.ListItem("1","1"),
                new Ext.Net.ListItem("2","2")
            };
    
            Ext.Net.ComboBox c2 = new ComboBox
            {
                ID = panelState.ID + "_c2"
            };
            c2.Items.AddRange(list2);
            c2.SelectedIndex = 0;
    
            c1.DirectEvents.Select.Event += new ComponentDirectEvent.DirectEventHandler(ColumnSelect);
            c1.DirectEvents.Select.ExtraParams.Add(new Ext.Net.Parameter("pId", panelState.ID, ParameterMode.Value));
    
            Ext.Net.Panel panel = new Ext.Net.Panel { ID = panelState.ID, Title = panelState.Title, TopBar = { new Toolbar { Items = { c1, c2 } } } };
            PanelsCt.Items.Add(panel);
            return panel;
        }
    
        void ColumnSelect(object sender, DirectEventArgs e)
        {
            string pId = e.ExtraParams["pId"];
            if (Page.FindControl(pId + "_c1") != null || Page.FindControl(pId + "_c2") != null)
            {
    
                Ext.Net.ComboBox c2 = (Ext.Net.ComboBox)Page.FindControl(pId + "_c2");
                var list3 = new ListItemCollection<Ext.Net.ListItem>
                {
                    new Ext.Net.ListItem("3","3"),
                    new Ext.Net.ListItem("4","4")
                };
                c2.Items.AddRange(list3);
                c2.SelectedIndex = 0;
                c2.Render();
            }
            else
            {
                X.Msg.Alert("Panel ID", "NULL").Show();
            }
        }
    
        protected void AddNewPanel(object sender, DirectEventArgs e)
        {
            PanelState state = new PanelState();
            panels.Add(state);
            state.ID = "id" + Guid.NewGuid().ToString().Replace("-", "");
            state.Title = "Panel №" + ++pkID + "   ;stateId   " + state.ID;
            CreatePanel(state).Render();
            PanelsCt.DoLayout();
        }
    }
  5. #5
    Hi,

    You have to set ID for Toolbar which you create in the CreatePanel
    Also render combo in ColumnSelect is not required, just rebind it
    c2.GetStore().DataBind();
  6. #6
    Thank you!
    It can work now.


    But I am sorry I can not find the function "GetStore().DataBind();" for Combobox control?
  7. #7
    Hi,

    But I am sorry I can not find the function "GetStore().DataBind();" for Combobox control?
    It can be if you use old version, latest code from SVN has GetStore method (please note that latest code uses ExtJS 3.3.0, it can break your custom extension (if you have it))

    Also, please see the following sample which demonstrates how to add/remove items
    https://examples1.ext.net/#/Form/Com...Items_Actions/
  8. #8
    Hello Vladimir,

    Quote Originally Posted by Vladimir View Post
    It can be if you use old version, latest code from SVN has GetStore method (please note that latest code uses ExtJS 3.3.0, it can break your custom extension (if you have it))
    I download the latest verion of today, and tried the function "GetStore().DataBind();" .
    It can run OK. Thanks.

Similar Threads

  1. Replies: 2
    Last Post: May 03, 2012, 3:12 PM
  2. Replies: 5
    Last Post: Dec 22, 2011, 11:38 AM
  3. [CLOSED] Always selected Item is nothing for combobox as menu item
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 04, 2011, 4:51 PM
  4. [CLOSED] Bug in Grouping of Grid if data is added dynamically
    By macap in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 25, 2010, 8:21 AM
  5. Replies: 4
    Last Post: Nov 17, 2008, 8:16 AM

Posting Permissions