【问题标题】:How to bind an empty collection object to a Data Grid?如何将空集合对象绑定到数据网格?
【发布时间】:2012-03-01 05:02:42
【问题描述】:

如何将空集合对象绑定到数据网格?当我按如下方式绑定它时,它会抛出“对象引用未设置为实例”错误。

grid1.DataSource = new CollectionClass(); grid1.DataBind();

【问题讨论】:

  • 您在哪一行收到此错误。查看堆栈跟踪。
  • 堆栈跟踪:[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
  • Infragistics.Web.UI.Framework.ObjectBase.SaveObjectClientProperties(IClientState webObject,StringBuilder 构建器)+34 Infragistics.Web.UI.Framework.ObjectBase.WriteClientCollections(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
  • Infragistics.Web.UI.GridControls.BaseGrid.SaveViewState() +69 Infragistics.Web.UI.GridControls.WebDataGrid.SaveViewState() +80 System.Web.UI.Control.SaveViewStateRecursive() + 187 System.Web.UI.Control.SaveViewStateRecursive() +106 System.Web.UI.Control.SaveViewStateRecursive() +106 System.Web.UI.Control.SaveViewStateRecursive() +106 System.Web.UI.Control.SaveViewStateRecursive( ) +106 System.Web.UI.Control.SaveViewStateRecursive() +106 System.Web.UI.Control.SaveViewStateRecursive() +106 System.Web.UI.Control.SaveViewStateRecursive() +106
  • 你为什么不在你的帖子的实际正文中包含堆栈跟踪?很难像这样阅读......

标签: asp.net infragistics


【解决方案1】:

您必须创建 CollectionClass() 的实例,然后绑定到 Grid。

CollectionClass() cc = new CollectionClass();
grid1.DataSource = cc; 
grid1.DataBind();

【讨论】:

  • 我上面的步骤不就是这样吗?
最近更新 更多