Issue with dynamic store and grid- Store is undefined

  1. #1

    Issue with dynamic store and grid- Store is undefined

    Hi,

    My requirement is to build a store and grid objects dynamically on click of button. I am always getting error as store is undefined. Please see below code and help me.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridColumns._Default" %>
    <%@ 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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server">
        </ext:ScriptManager>
        <ext:Panel ID="Panel1" runat="server" Frame="True" Height="300" Title="Title" Width="400px">
            <Body>
            </Body>
            <Buttons>
                <ext:Button ID="buttonone" runat="server" Text="Click me">
                    <AjaxEvents>
                        <Click OnEvent="button1_click">
                        </Click>
                    </AjaxEvents>
                </ext:Button>
            </Buttons>
        </ext:Panel>
        </form>
    </body>
    </html>
    C# code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Data;
    using System.Web.UI.WebControls;
    using Coolite.Ext.Web;
    
    namespace GridColumns
    {
        public partial class _Default : System.Web.UI.Page
        {
    
            protected void Page_Load(object sender, EventArgs e)
            {
            }
    
            public void button1_click(object sender, AjaxEventArgs e)
            {
                CreateDataGrid();
            }
    
            private void CreateDataGrid()
            {
                Store store = new Store();
                store.ID = "myStore";
                store.Reader.Add(new JsonReader() { ReaderID = "myreader" });
                Panel1.BodyControls.Add(store);
    
                GridPanel grid = new GridPanel();
                grid.ID = "mygrid";
                grid.Width = Unit.Pixel(100);
                grid.Height = Unit.Pixel(100);
                grid.StoreID = store.ClientID;
              
                DataTable dt = new DataTable("mytable");
                dt.Columns.Add("Name");
                dt.Columns.Add("Number");
    
                for (int i = 0; i < 5; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = "name" + i.ToString();
                    dr[1] = i.ToString();
                    dt.Rows.Add(dr);
                }
    
                foreach (DataColumn item in dt.Columns)
                {
                    RecordField r = new RecordField(item.ColumnName);
                    store.Reader[0].Fields.Add(r);
    
                    grid.ColumnModel.Columns.Add(new Column() { DataIndex = item.ColumnName, Header = item.ColumnName });
                }
                store.DataSource = dt;
                store.DataBind();
    
                Panel1.BodyControls.Add(store);
                Panel1.BodyControls.Add(grid);
               
            }
        }
    }

  2. #2

    RE: Issue with dynamic store and grid- Store is undefined

    Hi Hari,

    Dynamic creation of components is not supported during an AjaxEvent in v0.8.x.


    This will be possible in the upcoming v1.0 release.


    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] Dynamic store issue
    By digitek in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 07, 2012, 12:06 PM
  2. [CLOSED] Dynamic Store: undefined error at client side
    By digitek in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 16, 2011, 10:17 AM
  3. Replies: 12
    Last Post: Sep 20, 2011, 2:33 PM
  4. Replies: 0
    Last Post: Mar 04, 2011, 6:46 AM
  5. [CLOSED] Dynamic Grid/Store Issue
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Jun 16, 2010, 9:48 AM

Posting Permissions