2013-01-18 20 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

相關問題