2013-01-18 22 views
1

将某些代码移至服务器时遇到问题。代码在我的本地机器上运行良好。我在本地机器上访问此属性没有问题。但是,当我把它上传到我的开发服务器,我得到这个错误:访问对象属性时出错“在所选数据源上未找到名称为{PROPERTY_NAME}的字段或属性”

A field or property with the name 'CreatedBy.FullName' was not found on the selected data source.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the name 'CreatedBy.FullName' was not found on the selected data source. Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): A field or property with the name 'CreatedBy.FullName' was not found on the selected data source.] System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer) +1788095 System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender, EventArgs e) +67 System.Web.UI.Control.OnDataBinding(EventArgs e) +91 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92 System.Web.UI.Control.DataBind() +15 System.Web.UI.Control.DataBindChildren() +201 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101 System.Web.UI.Control.DataBind() +15 System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +166 System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3098 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66 System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

这里是aspx页面的样子(SNIP):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" DataKeyNames="ApplicationID" CellPadding="4" ForeColor="#333333" GridLines="None"> 
     <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
     <Columns> 
      <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" /> 
      <asp:HyperLinkField DataNavigateUrlFields="applicationID" DataNavigateUrlFormatString="~/Admin/ManageRoles.aspx?applicationID={0}" Text="View App Roles" /> 
      <asp:HyperLinkField DataNavigateUrlFields="applicationID" DataNavigateUrlFormatString="~/Admin/ManageApplicationUsers.aspx?applicationID={0}" Text="View App Users" /> 
      <asp:BoundField DataField="ApplicationID" HeaderText="ApplicationID" ReadOnly="True" SortExpression="ApplicationID" /> 
      <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 
      <asp:TemplateField HeaderText="Description" SortExpression="Description"> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>' TextMode="MultiLine"></asp:TextBox> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Description") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:BoundField DataField="CreatedBy.FullName" HeaderText="Created By" SortExpression="CreatedByID" ReadOnly="True" /> 
      <asp:BoundField DataField="CreatedDate" HeaderText="CreatedDate" ReadOnly="True" SortExpression="CreatedDate" /> 
      <asp:BoundField DataField="ModifiedBy.FullName" HeaderText="Modified By" SortExpression="ModifiedByID" NullDisplayText="&lt;i&gt;null&lt;/i&gt;" ReadOnly="True" /> 
      <asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate" ReadOnly="True" SortExpression="ModifiedDate" NullDisplayText="&lt;i&gt;null&lt;/i&gt;" /> 
     </Columns> 
<!-- SNIP: styling --> 
</asp:GridView> 

UPDATE 我已经通过使用解决方法让我的代码运行。如果我使用模板字段而不是绑定字段,它将运行。例如,我用这个:

<asp:TemplateField HeaderText="Description" SortExpression="Description"> 
       <EditItemTemplate> 
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CreatedBy.FullName") %>' TextMode="MultiLine"></asp:TextBox> 
       </EditItemTemplate> 
       <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CreatedBy.FullName") %>'></asp:Label> 
       </ItemTemplate> 
      </asp:TemplateField> 

,而不是这样的:

<asp:BoundField DataField="CreatedBy.FullName" HeaderText="Created By" SortExpression="CreatedByID" ReadOnly="True" /> 

我很高兴它的工作现在,但坦率地说,我想知道的问题是什么呢!

+0

您是否正在使用Telerik? – Brian

+0

不适用于此项目。 – solidau

+0

“datasource”的名称拼写是否正确?你是否指出了正确的'datasource'?如同,你的本地'数据源'是否与你在推送你的代码时指出的'数据源'相同? – Brian

回答

1

回答你的问题是这样的:

一个BoundField显示从您的datasource文本信息和TemplateField允许HTMLWebControlsdata-binding语法的混合物。

+0

我知道不同的控件做什么。我不明白的是为什么它在绑定字段的本地机器上工作,但不能作为绑定字段在服务器上工作(这就是我将它们切换到模板字段的原因)。正如你所看到的,我的模板只是纯文本的,所以我觉得我应该能够使用绑定字段,它可以在我的本地而不是在服务器上运行。 – solidau

+0

我不得不同意,因为你的模板只是文本。但是,我不知道我甚至可能会猜测为什么它在本地工作而不是在服务器上工作,而没有先看到一些代码。 – Brian

相关问题