asp.net – DataBinding:’System.Data.DataRowView’不包含名称的属性

前端之家收集整理的这篇文章主要介绍了asp.net – DataBinding:’System.Data.DataRowView’不包含名称的属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我得到这个奇怪的错误…我的数据库中的主键是’DocumentID’,所以我知道这不是问题.我正在尝试选择,编辑和删除gridview按钮工作,但我需要正确设置datakeynames以供他们使用.有任何想法吗?
  1. <asp:GridView ID="GridView1" runat="server" DataSourceID="sdsDocuments" EnableModelValidation="True"
  2. SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" DataKeyNames="DocumentID,DocumentTitle,DocumentBody">
  3. <Columns>
  4. <asp:BoundField DataField="DocumentID" HeaderText="DocumentID" ReadOnly="True" SortExpression="ID" />
  5. <asp:BoundField DataField="DocumentTitle" HeaderText="DocumentTitle" SortExpression="Title" />
  6. <asp:BoundField DataField="DocumentBody" HeaderText="DocumentBody" SortExpression="Body" />
  7. <asp:CommandField ShowSelectButton="True" ShowDeleteButton="True" />
  8. </Columns>
  9. </asp:GridView>
  10. <asp:sqlDataSource ID="sdsDocuments" runat="server" ConnectionString="<%$ConnectionStrings:blcDocumentationConnectionString %>"
  11. SelectCommand="SELECT [DocumentTitle],[DocumentBody] FROM [tblDocument]" />

这是堆栈跟踪…

  1. [HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'DocumentID'.]
  2. System.Web.UI.DataBinder.GetPropertyValue(Object container,String propName) +8672869
  3. System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource,Boolean dataBinding) +2178
  4. System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
  5. System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
  6. System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
  7. System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,DataSourceViewSelectCallback callback) +31
  8. System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
  9. System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
  10. System.Web.UI.WebControls.GridView.DataBind() +4
  11. System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
  12. System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
  13. System.Web.UI.Control.EnsureChildControls() +87
  14. System.Web.UI.Control.PreRenderRecursiveInternal() +44
  15. System.Web.UI.Control.PreRenderRecursiveInternal() +171
  16. System.Web.UI.Control.PreRenderRecursiveInternal() +171
  17.  
  18. System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +842

解决方法

那么你没有选择documentid列,因此它不存在于datatable或dataview中,它们绑定到grid或通过datatable引用该列.

将您的查询更改为

  1. SelectCommand="SELECT [DocumentID],[DocumentTitle],[DocumentBody] FROM [tblDocument]" />

猜你在找的asp.Net相关文章