如何將空集合對象綁定到數據網格?當我像下面那樣綁定它時,會拋出「對象引用未設置爲實例」的錯誤。如何將空集合對象綁定到數據網格?
grid1.DataSource = new CollectionClass(); grid1.DataBind();
如何將空集合對象綁定到數據網格?當我像下面那樣綁定它時,會拋出「對象引用未設置爲實例」的錯誤。如何將空集合對象綁定到數據網格?
grid1.DataSource = new CollectionClass(); grid1.DataBind();
您將不得不創建CollectionClass()的實例,然後綁定到網格。
CollectionClass() cc = new CollectionClass();
grid1.DataSource = cc;
grid1.DataBind();
是不是我在上面的步驟中做了什麼? – user536652 2012-03-01 05:46:16
嘗試編輯答案。 – Saurabh 2012-03-01 05:49:41
試過了。沒有運氣 – user536652 2012-03-01 06:31:36
哪條線是你得到這個錯誤。查看堆棧跟蹤。 – deostroll 2012-03-01 05:48:31
堆棧跟蹤: [NullReferenceException異常:未設置爲一個對象的實例對象引用] Infragistics.Web.UI.GridControls.JsTypeResolver.ResolveTypeId(類型類型)450 Infragistics.Web.UI.GridControls.GridField。 SaveClientProperties()120個 Infragistics.Web.UI.GridControls.FormattedGridField.SaveClientProperties()30個 Infragistics.Web.UI.GridControls.BoundDataField.SaveClientProperties()29個 Infragistics.Web.UI.Framework.ObjectBase.Infragistics .Web.UI.IClientState.SaveClientProperties()+31 – user536652 2012-03-01 06:29:26
Infragistics.Web.UI.Framework.ObjectBase.SaveObjectClientProperties(IClientState webObject,StringBuilder構建器)+34 Infragistics.Web.UI.Framework.ObjectBase.Wr iteClientCollections(StringBuilder構建器,ArrayList集合)+649 Infragistics.Web.UI.Framework.ObjectBase.SaveCollectionsStateToViewState()+165 Infragistics.Web.UI.Framework.RunBot.HandleSaveViewState()+82 Infragistics.Web.UI.Framework .Data.FlatDataBoundControl.SaveViewState()+108 – user536652 2012-03-01 06:30:14