[CLOSED] something is missing. Grid not loading data from List<>

  1. #1

    [CLOSED] something is missing. Grid not loading data from List<>

    I was trying to build a simple example for another problem and load some static data into a grid.

    <%@ Page Language="C#" %>
    <%@ 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">
    
    <script runat="server">
        public class CustObj
        {
            public int ID;
            public string Name;
            public string EMail;
    
            public CustObj(int id, string name, string email)
            {
                ID = id;
                Name = name;
                EMail = email;
            }
            public CustObj(int id, string name) : this(id, name, string.Format("a{0}@email.com", id)) { }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                System.Collections.Generic.List<CustObj> source = new System.Collections.Generic.List<CustObj>();
                source.Add(new CustObj( 1, "3m Co"));
                source.Add(new CustObj( 2, "Alcoa Inc"));
                source.Add(new CustObj( 3, "Altria Group Inc"));
                source.Add(new CustObj( 4, "American Express Company"));
                source.Add(new CustObj( 5, "American International Group, Inc."));
                source.Add(new CustObj( 6, "AT&amp;T Inc."));
                source.Add(new CustObj( 7, "Boeing Co."));
                source.Add(new CustObj( 8, "Caterpillar Inc."));
                source.Add(new CustObj( 9, "Citigroup, Inc."));
                source.Add(new CustObj(10, "E.I. du Pont de Nemours and Company"));
                source.Add(new CustObj(11, "Exxon Mobil Corp"));
                source.Add(new CustObj(12, "General Electric Company"));
                source.Add(new CustObj(13, "General Motors Corporation"));
                source.Add(new CustObj(14, "Hewlett-Packard Co."));
                source.Add(new CustObj(15, "Honeywell Intl Inc"));
                source.Add(new CustObj(16, "Intel Corporation"));
                source.Add(new CustObj(17, "International Business Machines"));
                source.Add(new CustObj(18, "Johnson &amp; Johnson"));
                source.Add(new CustObj(19, "JP Morgan &amp; Chase &amp; Co"));
                source.Add(new CustObj(20, "McDonald\"s Corporation"));
                source.Add(new CustObj(21, "Merck &amp; Co., Inc."));
                source.Add(new CustObj(22, "Microsoft Corporation"));
                source.Add(new CustObj(23, "Pfizer Inc"));
                source.Add(new CustObj(24, "The Coca-Cola Company"));
                source.Add(new CustObj(25, "The Home Depot, Inc."));
                source.Add(new CustObj(26, "The Procter &amp; Gamble Company"));
                source.Add(new CustObj(27, "United Technologies Corporation"));
                source.Add(new CustObj(28, "Verizon Communications"));
                source.Add(new CustObj(29, "Wal-Mart Stores, Inc."));
    
                this.SearchStore.DataSource = source;
                this.SearchStore.DataBind();
            }
        }
    
        #region Events
        protected void RowSelect(object sender, Coolite.Ext.Web.AjaxEventArgs e)
        {
        }
    
        protected void btnAddMailing_Click(object sender, Coolite.Ext.Web.AjaxEventArgs e)
        {
            string selected = string.Empty;
            try
            {
                foreach (Coolite.Ext.Web.SelectedRow row in SelectionModel1.SelectedRows)
                {
                    int custID = Convert.ToInt32(row.RecordID);
                    selected += (selected.Length > 0 ? ", " : "") + row.RecordID;
                }
            }
            catch (Exception x)
            {
                this.gridCustomerList.AddScript("Ext.MessageBox.show({title: 'Error',  msg: '" + x.Message + "', buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.ERROR });");
                return;
            }
    
            this.gridCustomerList.AddScript("Ext.MessageBox.show({title: 'Selected Rows',  msg: '" + (selected.Length > 0 ? selected : "NONE") + "', buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.INFO });");
    
            RowSelectionModel sm = this.gridCustomerList.SelectionModel.Primary as RowSelectionModel;
            sm.SelectedRows.Clear();
            sm.UpdateSelection();
        }
        #endregion
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
    
        <form id="form2" runat="server">
        
        <ext:ScriptManager ID="ScriptManager1" runat="server" Theme="Gray" />
    
        <ext:Store ID="SearchStore" runat="server">
            <Reader>
                <ext:JsonReader ReaderID="ID">
                    <Fields>
                        <ext:RecordField Name="Name" />
                        <ext:RecordField Name="EMail" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
    
        <ext:GridPanel ID="gridCustomerList" runat="server" AutoExpandColumn="Name" StoreID="SearchStore" Border="false" Height="400">
            <ColumnModel ID="gridCustomerListColumnModel" runat="server">
                <Columns>
                    <ext:Column ColumnID="Name" DataIndex="Name" Header="Name" />
                    <ext:Column ColumnID="EMail" DataIndex="EMail" Header="E-Mail" />
                </Columns>
            </ColumnModel>
            
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="SelectionModel1" runat="server" SingleSelect="false">
                    <AjaxEvents>
                        <SelectionChange OnEvent="RowSelect" Buffer="250">
                            <EventMask ShowMask="true" Target="CustomTarget" Msg="Loading..." CustomTarget="#{Details}"/>
                        </SelectionChange>
                    </AjaxEvents>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            
            <Buttons>
                <ext:Button ID="btnAddMailing" runat="server" Text="Add selected to mailing list" Icon="EmailAdd">
                    <AjaxEvents>
                        <Click OnEvent="btnAddMailing_Click" >
                            <EventMask ShowMask="true" Target="Page" Msg="Processing..." />
                        </Click>
                    </AjaxEvents>
                </ext:Button>
            </Buttons>
            
            <BottomBar>
                <ext:PagingToolBar ID="ListPagination" runat="server" StoreID="SearchStore" PageSize="100" >
                    <Plugins>
                        <ext:SlidingPager ID="SlidingPager1" runat="server">
                            <GetText Fn="function(s){return s.value}" />
                        </ext:SlidingPager>
                    </Plugins>
                </ext:PagingToolBar>
            </BottomBar>
            
            <LoadMask ShowMask="true" />
            
        </ext:GridPanel>
        
        </form>
    </body>
    </html>
    but the data does not load. No error appears but the grid stays empty.

  2. #2

    RE: [CLOSED] something is missing. Grid not loading data from List<>

    Hi,

    You need use properties in CustObj. We (and classic ASP.NET data source objects) reflect properties only. Give public access to fields is bad practice. So, if you add properties to this object then all should works
  3. #3

    RE: [CLOSED] something is missing. Grid not loading data from List<>

    ok, this works

    ...
            public int ID { get; set; }
            public string Name { get; set; }
            public string EMail { get; set; }
    ...
    you can mark this one as solved

Similar Threads

  1. [CLOSED] missing } after property list with JsonReader
    By krzak in forum 1.x Legacy Premium Help
    Replies: 26
    Last Post: May 19, 2011, 3:40 PM
  2. [CLOSED] Loading Mask Before data bind to grid
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Apr 27, 2011, 12:22 PM
  3. Replies: 4
    Last Post: Mar 24, 2011, 2:37 PM
  4. BADRESPONSE: missing } after property list
    By designworxz in forum 1.x Help
    Replies: 7
    Last Post: Feb 17, 2009, 8:47 PM
  5. [CLOSED] "missing } after property list" error
    By stevejebson in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Sep 30, 2008, 7:45 PM

Posting Permissions