Aug 28, 2012, 10:56 AM
[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:
P.K.
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.5P.K.
Last edited by Daniil; Aug 29, 2012 at 7:13 AM.
Reason: [CLOSED]