solidau
solidau

Reputation: 4081

Error accessing Object Property "A field or property with the name {PROPERTY_NAME} was not found on the selected data source"

Having trouble with some code when moving it to a server. The code runs fine on my local machine. I have no problem accessing this property on my local machine. But, when I Upload it to my development server, I get this error:

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

Here is what the aspx page looks like (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 I've got my code to run by using a workaround. If I use a template field instead of bound field, it will run. for example, I use this:

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

instead of this:

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

I'm glad it's working now, but frankly, I'd like to know what the problem was too!

Upvotes: 1

Views: 2404

Answers (1)

Brian
Brian

Reputation: 5119

The answer to your question is this:

A BoundField displays the information from your datasource as text and the TemplateField allows for a mixture of HTML, WebControls and also data-binding syntax.

Upvotes: 1

Related Questions