[CLOSED] How to change Store from DirectEvent?

  1. #1

    [CLOSED] How to change Store from DirectEvent?

    Hello,

    Is there a way to chage a store (for example in ComboBox) from DirectEvent (codebehind) ?

    In my example I have one combo-box, 2 buttons and 2 stores.
    Button1.click should load and display store1, button2 - store2.

    But this is not working.. only store1 is "attached".

    I've discovered that if no store is added to combo1 StoreCollection (in constructor), the combo1.store remains default (SimpleStore).

    Sample code:

    test8.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test8.aspx.cs" Inherits="test8" %>
    
    <!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">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    test8.aspx.cs:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Data;
    using Ext.Net;
    
    public class dict_store : Ext.Net.Store
    {
    
      DataTable data_table;
    
      public dict_store(string id_)
      {
        this.ID = id_;
        this.Reader.Add(new JsonReader());
    
        data_table = new DataTable();
        data_table.Columns.Add("value");
        data_table.Columns.Add("text");
        this.AddField(new RecordField("value"));
        this.AddField(new RecordField("text"));
        this.DataSource = data_table;
    
      }
    
      public void load_dict()
      {
        // sample dynamic data
        data_table.Rows.Clear();
        data_table.Rows.Add(new string[2] { "1", "text 1 in " + this.ID });
        data_table.Rows.Add(new string[2] { "2", "text 2 in " + this.ID });
        data_table.Rows.Add(new string[2] { "3", "text 3 in " + this.ID });
        this.DataBind();    
      }
     
    }
    
    
    public class dict_combo : ComboBox
    {
    
      private dict_store store1;
      private dict_store store2;
    
      public dict_combo(string id_, string label_)
      {
        this.ID = id_;
        this.FieldLabel = label_;
        this.ValueField = "value";
        this.DisplayField = "text";    
        this.Width = 300;
        this.LabelWidth = 100;
        this.ListWidth = 200;
    
        this.Mode = DataLoadMode.Local;
        this.TriggerAction = TriggerAction.All;
        store1 = new dict_store("store1_for_" + this.ID);
        this.Store.Add(store1);
    
        store2 = new dict_store("store2_for_" + this.ID);
        store2.Render(); // must be rendered to be accessible later
    
      }
    
      protected override void OnLoad(EventArgs e)
      {
        if (!ExtNet.IsAjaxRequest)
        {
          ExtNet.ResourceManager.AddDirectMethodControl(this);
        }
      }
    
      [DirectMethod]
      public void load_dict_1()
      {
        store1.load_dict();
        this.Store.Clear();    
        this.Store.Add(store1);
      }
      
      [DirectMethod]
      public void load_dict_2()
      {
        store2.load_dict();
        this.Store.Clear();
        this.Store.Add(store2);
      }
    
    }
    
    
    public partial class test8 : System.Web.UI.Page
    {
    
      protected void Page_Load(object sender, EventArgs e)
      {
    
        var res_man = new ResourceManager();
        res_man.DisableViewState = false;
        res_man.DirectMethodNamespace = "dm";
        res_man.IDMode = IDMode.Explicit; // explicit client IDs
        form1.Controls.Add(res_man);
    
        var combo1 = new dict_combo("combo1", "Select value");
    
        var button1 = new Button("Load dict 1");
        button1.Listeners.Click.Handler = "dm.combo1.load_dict_1();";
    
        var button2 = new Button("Load dict 2");
        button2.Listeners.Click.Handler = "dm.combo1.load_dict_2();";
        
        form1.Controls.Add(combo1);
        form1.Controls.Add(button1);
        form1.Controls.Add(button2);
      }
    
    }
    Ext.net 1.5

    P.K.
    Last edited by Daniil; Aug 29, 2012 at 7:13 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "item 1" },
                    new object[] { "2", "item 2" },
                    new object[] { "3", "item 3" }
                };
                store.DataBind();
                
                this.AnotherStore.DataSource = new object[] 
                { 
                    new object[] { "5", "item 5" },
                    new object[] { "6", "item 6" },
                    new object[] { "7", "item 7" }
                };
                this.AnotherStore.DataBind();
            }
        }
    
        protected void ChangeStore(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Store.Clear();
            this.ComboBox1.StoreID = "AnotherStore";
            this.ComboBox1.Render(); 
        }
    </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:Container runat="server">
                <Items>
                    <ext:ComboBox ID="ComboBox1" runat="server">
                        <Store>
                            <ext:Store runat="server">
                                <Reader>
                                    <ext:ArrayReader>
                                        <Fields>
                                            <ext:RecordField Name="value" />
                                            <ext:RecordField Name="text" />
                                        </Fields>
                                    </ext:ArrayReader>
                                </Reader>
                            </ext:Store>
                        </Store>
                    </ext:ComboBox>
                </Items>
            </ext:Container>
    
            <ext:Store ID="AnotherStore" runat="server">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="value" />
                            <ext:RecordField Name="text" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
    
            <ext:Button runat="server" Text="Change Store" OnDirectClick="ChangeStore" />
        </form>
    </body>
    </html>
    Do you really need to use two Stores?

    What about to use a single Store and just bind with respective data on demand?
  3. #3
    Good idea :)
    It also made my code simpler. Thanks.

Similar Threads

  1. [CLOSED] Change the BackColor of a Control during DirectEvent
    By dmoore in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Nov 29, 2011, 2:44 PM
  2. Directevent on ext:combobox change
    By Rupesh in forum 1.x Help
    Replies: 2
    Last Post: Sep 16, 2010, 1:47 PM
  3. [CLOSED] Change ComboBox items during DirectEvent
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Sep 16, 2010, 9:08 AM
  4. [CLOSED] ComboBox with Change DirectEvent
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 03, 2010, 7:31 PM
  5. [CLOSED] [1.0] DirectEvent JsonConverter Change...
    By rcaunt in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 10, 2010, 5:03 PM

Posting Permissions