PDA

View Full Version : Dynamic Create GridPanel and Load Data Error



fancycloud
Oct 23, 2009, 3:49 AM
Hi,everybody,In My One Project,IWant to Dynamic Create GridPanel and Load Data,
And I Write the Code By C# Code,but I Had get Error.

This is My Code:



protected void Page_Load(object sender, EventArgs e)
{
if (!Ext.IsAjaxRequest)
{
CreateGridPanel();


}
}



private void CreateGridPanel()
{


Store MyStore = new Store();
MyStore.ID = "StoreData";
//MyStore.
JsonReader basereader = new JsonReader();
basereader.ReaderID = "BaseID";
RecordField Field0 = new RecordField("id");
RecordField Field1 = new RecordField("FormName");
RecordField Field2 = new RecordField("FormCaption");
RecordField Field3 = new RecordField("DLLName");
basereader.Fields.Add(Field0);
basereader.Fields.Add(Field1);
basereader.Fields.Add(Field2);
basereader.Fields.Add(Field3);


MyStore.Reader.Add(basereader);
DataTable TempTable = DBUtility.SQLHelper.ExecuteTable(CommandType.Text, "Select * from BaseForm", null);




FormPanel MyPanel = new FormPanel();
MyPanel.Width = 500;
MyPanel.Header = true;
MyPanel.Title = "Test Model";
MyPanel.Frame = true;
this.Controls.Add(MyPanel);


GridPanel TempPanel = new GridPanel();


TempPanel.StripeRows = true;
TempPanel.StoreID = MyStore.ID;
TempPanel.Height = 300;
TempPanel.Width = 400;

foreach (DataColumn OldColumn in TempTable.Columns)
{
Column TempColumn = new Column();
TempColumn.DataIndex = OldColumn.ColumnName;
TempColumn.Header = OldColumn.Caption;


TempPanel.ColumnModel.Columns.Add(TempColumn);
}





MyPanel.BodyControls.Add(TempPanel);
MyStore.DataSource = TempTable;
MyStore.DataBind();
}


On run the Code,It Get this Error

<H1>?/WebSite4?????????????
<HR width="100%" color=silver SIZE=1>
</H1>
<H2>The Control with ID = 'StoreData' not found </H2>


??: ???? Web ????,??????????????????,??????????????????????????

??????: System.InvalidOperationException: The Control with ID = 'StoreData' not found

???:


<TABLE width="100%" bgColor=#ffffcc>
<TBODY>
<TR>
<TD><CODE>???? Web ??????????????????????????????????????????????</CODE> </TD></TR></TBODY></TABLE>
????:


<TABLE width="100%" bgColor=#ffffcc>
<TBODY>
<TR>
<TD><CODE>[InvalidOperationException: The Control with ID = 'StoreData' not found]
Coolite.Ext.Web.ClientConfig.ToExtConfig(PropertyI nfo property, Object obj, ClientConfigAttribute attr, Object defaultValue) +4279
Coolite.Ext.Web.ClientConfig.Process(Object obj) +277

[Exception: Error during ClientConfig initialization. StoreID - The Control with ID = 'StoreData' not found]
Coolite.Ext.Web.ClientConfig.Process(Object obj) +470
Coolite.Ext.Web.ClientConfig.Serialize(Object obj, Boolean ignoreCustomSerialization) +846
Coolite.Ext.Web.ClientConfig.Serialize(Object obj) +39
Coolite.Ext.Web.WebControl.get_InitialConfig() +90
Coolite.Ext.Web.WebControl.GetClientConstructor(Bo olean instanceOnly, String body) +662
Coolite.Ext.Web.WebControl.GetClientConstructor() +37
Coolite.Ext.Web.WebControl.OnClientInit() +141
Coolite.Ext.Web.Observable.OnClientInit() +39
Coolite.Ext.Web.WebControl.SetResources() +116
Coolite.Ext.Web.WebControl.PreRenderAction() +62
Coolite.Ext.Web.Observable.PreRenderAction() +399
Coolite.Ext.Web.WebControl.Render(HtmlTextWriter writer) +132
Coolite.Ext.Web.Container.Render(HtmlTextWriter writer) +146
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +19
System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter writer) +32
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +19
System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter writer) +10
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +32
Coolite.Ext.Web.WebControl.Render(HtmlTextWriter writer) +363
Coolite.Ext.Web.Container.Render(HtmlTextWriter writer) +146
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
</PRE></CODE></TD></TR></TBODY></TABLE>

<HR width="100%" color=silver SIZE=1>



????: Microsoft .NET Framework ??:2.0.50727.3053; ASP.NET ??:2.0.50727.3053

And I Don not Know How to Slove it ,Can Someone Help Me? Thanks.<!--
[InvalidOperationException]: The Control with ID = 'StoreData' not found
? Coolite.Ext.Web.ClientConfig.ToExtConfig(PropertyI nfo property, Object obj, ClientConfigAttribute attr, Object defaultValue)
? Coolite.Ext.Web.ClientConfig.Process(Object obj)
[Exception]: Error during ClientConfig initialization. StoreID - The Control with ID = 'StoreData' not found
? Coolite.Ext.Web.ClientConfig.Process(Object obj)
? Coolite.Ext.Web.ClientConfig.Serialize(Object obj, Boolean ignoreCustomSerialization)
? Coolite.Ext.Web.ClientConfig.Serialize(Object obj)
? Coolite.Ext.Web.WebControl.get_InitialConfig()
? Coolite.Ext.Web.WebControl.GetClientConstructor(Bo olean instanceOnly, String body)
? Coolite.Ext.Web.WebControl.GetClientConstructor()
? Coolite.Ext.Web.WebControl.OnClientInit()
? Coolite.Ext.Web.Observable.OnClientInit()
? Coolite.Ext.Web.WebControl.SetResources()
? Coolite.Ext.Web.WebControl.PreRenderAction()
? Coolite.Ext.Web.Observable.PreRenderAction()
? Coolite.Ext.Web.WebControl.Render(HtmlTextWriter writer)
? Coolite.Ext.Web.Container.Render(HtmlTextWriter writer)
? System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
? System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children)
? System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
? System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter writer)
? System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
? System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children)
? System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
? System.Web.UI.WebControls.WebControl.RenderContent s(HtmlTextWriter writer)
? System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
? Coolite.Ext.Web.WebControl.Render(HtmlTextWriter writer)
? Coolite.Ext.Web.Container.Render(HtmlTextWriter writer)
? System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
? System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children)
? System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
? System.Web.UI.Page.Render(HtmlTextWriter writer)
? System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
? System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
? System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: ??????System.Web.HttpUnhandledException?????
? System.Web.UI.Page.HandleError(Exception e)
? System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
? System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
? System.Web.UI.Page.ProcessRequest()
? System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
? System.Web.UI.Page.ProcessRequest(HttpContext context)
? ASP.default_aspx.ProcessRequest(HttpContext context) ?? c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\website4\0d8d8ae9\2b6cd259\App_Web_ilyhbcqy. 0.cs:?? 0
? System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
? System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
-->

plykkegaard
Nov 01, 2009, 5:12 PM
I have added the store in the markup file (aspx) not in the codebehind class (aspx.cs)
eg

<ext:Store ID="store" runat="Server"
DataSourceID="sqlDataSource"
OnBeforeAjaxEvent="store_BeforeAjaxEvent"
OnAfterAjaxEvent="store_AfterAjaxEvent"
OnBeforeRecordDeleted="store_BeforeRecordDeleted"
OnAfterRecordDeleted="store_AfterRecordDeleted"
OnBeforeRecordUpdated="store_BeforeRecordUpdated"
OnAfterRecordUpdated="store_AfterRecordUpdated"
OnBeforeRecordInserted="store_BeforeRecordInserted"
OnAfterRecordInserted="store_AfterRecordInserted"
OnAfterStoreChanged="store_AfterStoreChanged"
OnRefreshData="store_RefreshData"
OnSubmitData="store_Submit"
>
<AjaxEventConfig IsUpload="true" />
</ext:Store>

hth

thunderstorm
Jan 05, 2010, 2:52 AM
You may need to add some code



MyPanel.BodyControls.Add(MyStore);