Store Data is not displaying in Dynamic Gridpanel

  1. #1

    Store Data is not displaying in Dynamic Gridpanel

    Hi, I am creating a dynamic store and dynamic gridpanel from the code behind.After that i am adding that gridpanel into a window through a code behind.But That dynamic data is not displaying in gridpanel.Only header is displaying.i am using this code.


    <%@ Page Language="C#" AutoEventWireup="true">
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
          <ext:Window 
                ID="Window1" 
                runat="server" 
                Title="Window1"  
                Icon="Application"
                Height="135px" 
                Width="450px"
                BodyStyle="background-color: #fff;" 
                Padding="5"
                Collapsible="true" 
                Modal="true" Hidden="true">
                
            </ext:Window>  
        <ext:Button ID="Button1" runat="server" Text="Create a grid" OnDirectClick="RenderGrid" />
            
          
            
        </form>
    </body>
    </html>
    protected void RenderGrid(object sender, DirectEventArgs e)
            {
                string s0 = "Very Good";
                string s1 ="Good";
                string s2 = "Poor";
                string cnt0 = "2";
                string cnt1 = "1";
                string cnt2 = "0";
    
    
                JsonReader jr = new JsonReader();
                Store store = new Store()
                {
                    ID = "Store2"
                };
    
                jr.Fields.Add(new RecordField(s0));
                jr.Fields.Add(new RecordField(s1));
                jr.Fields.Add(new RecordField(s2));
    
    
                store.Reader.Add(jr);
    
                store.DataSource = new List<object>()
            {
                new
                {
                    s0 = cnt0,s1=cnt1,s2=cnt2
                }
                
                
            };
    
                store.DataBind();
    
                GridPanel grid = new GridPanel()
                {
                    ID = "GridPanel2",
                    Width = 300,
                    AutoHeight = true
                };
                grid.Store.Add(store);
    
                grid.ColumnModel.Columns.Add(new Column()
                {
                    Header = s0,
                    DataIndex = s0,
                    Width = 180
                });
    
                grid.ColumnModel.Columns.Add(new Column()
                {
                    Header = s1,
                    DataIndex = s1,
                    Width = 80
                });
                grid.ColumnModel.Columns.Add(new Column()
                {
                    Header = s2,
                    DataIndex = s2,
                    Width = 80
                });
    
               
                grid.AddTo(this.Window1);
    
                Window1.Show();
                
                
    
    
            }
    Displaying header only.Please help me.
  2. #2
    Hi,

    The problem is here:
    store.DataSource = new List<object>()
    {
        new
        {
            s0 = cnt0, s1 = cnt1, s2 = cnt2
        }
    };
    There will be an object with "s0", "s1" and "s2" properties, not "Very Good", "Good" and "Poor" ones which you place into the local variables s0, s1, s2.

    If you replace it with:
    store.DataSource = new List<object>()
    {
        new
        {
            VeryGood = cnt0, 
            Good = cnt1,
            Poor = cnt2
        }
    };
    and
    string s0 = "Very Good";
    with
    string s0 = "VeryGood";
    you will see this data in the GridPanel.

Similar Threads

  1. Store Data is not displaying in Dynamic Gridpanel
    By rendongsc in forum 1.x Help
    Replies: 1
    Last Post: Apr 11, 2012, 9:19 PM
  2. Replies: 1
    Last Post: Mar 08, 2012, 2:52 PM
  3. Replies: 0
    Last Post: Mar 04, 2011, 12:05 PM
  4. Replies: 1
    Last Post: Oct 27, 2009, 10:39 AM
  5. Dynamic Store/Grid Load on Postback - no data.
    By rthiney in forum 1.x Help
    Replies: 4
    Last Post: Aug 12, 2009, 7:38 AM

Posting Permissions