1

将某些代码移至服务器时遇到问题。代码在我的本地机器上运行良好。我在本地机器上访问这个属性没有问题。但是,当我将它上传到我的开发服务器时,我收到了这个错误:

在所选数据源上找不到名为“CreatedBy.FullName”的字段或属性。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Web.HttpException:在所选数据源上找不到名为“CreatedBy.FullName”的字段或属性。源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪:

[HttpException (0x80004005):在所选数据源上找不到名为“CreatedBy.FullName”的字段或属性。] 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(布尔 raiseOnDataBinding) +101 System.Web.UI.Control.DataBind() +15 系统.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem,DataControlField[] 字段、TableRowCollection 行、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 数据)+14 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable 数据)+128 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments 参数,DataSourceViewSelectCallback 回调) +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(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+2496WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 系统。 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(布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)+2496WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 系统。 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(布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)+2496PreRenderRecursiveInternal() +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) + 2496PreRenderRecursiveInternal() +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) + 2496Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)+2496Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(布尔型 includeStagesBeforeAsyncPoint,布尔型 includeStagesAfterAsyncPoint)+2496

这是 aspx 页面的样子(截图):

<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>

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

<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" />

我很高兴它现在可以工作,但坦率地说,我也想知道问题所在!

4

1 回答 1

1

你的问题的答案是这样的:

ABoundField显示来自您datasource文本的信息,并且TemplateField允许混合使用HTML,WebControlsdata-binding语法。

于 2013-01-18T21:27:32.720 回答