Apr 14, 2009, 11:33 AM
[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&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 & Johnson"));
source.Add(new CustObj(19, "JP Morgan & Chase & Co"));
source.Add(new CustObj(20, "McDonald\"s Corporation"));
source.Add(new CustObj(21, "Merck & 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 & 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.