Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "A field or property with the name was not found on the selected data source" get only on server

I publish my project without any warning on local iis and it works correctly (localhost/[myprojectName]). so, i upload them to server with cute ftp. but in server i get this error apear for all my filed like [tableName].[filedName]:

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

here's my code:

<asp:GridView ID="ordergv" runat="server" DataKeyNames="Id" AutoGenerateColumns="False" DataSourceID="SummaryOfOrderSrc" AllowSorting="True">
    <Columns>
        <asp:CommandField SelectText="select" ShowSelectButton="True" ButtonType="Button"/>
        <asp:BoundField DataField="OrderId"  />
        <asp:BoundField DataField="ConfirmStatuse.Name"  />
        <asp:BoundField DataField="OrderStatuse.Name"/>
        <asp:BoundField DataField="PaymentStatuse.Name"/>
        <asp:BoundField DataField="ShipmentStatuse.Name" />
        <asp:TemplateField >
            <ItemTemplate>
          <asp:Label ID="CreatedDateLabel" runat="server" Text='<%# GetPersianDate( Eval("CreatedDate")) %>' /></ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

<asp:LinqDataSource ID="SummaryOfOrderSrc" runat="server" ContextTypeName="Ahooratech.DAL.DataClasses1DataContext" EntityTypeName="" OrderBy="CreatedDate desc" TableName="Orders">
</asp:LinqDataSource>

I check the size of my project in local iis and on server. both of them are same(8,459,009 bytes)

so it means i use same database and same files for run my application for run on local and server. so why i get this error only in server?

The only difference here is on version of iis, i think my server iis version is 7.0. but is it important for i get this error?!!! i don't think so. i'm really confused.

(My local project and server project use same connection string).

EDIT: I publish project on another host and it works! but it doesn't work on my original server yet.

like image 436
Mohammadreza Avatar asked Jun 15 '13 05:06

Mohammadreza


2 Answers

This is the same issue to the one described here - Binding to Navigation Property causes " A field or property with the name 'X.X' was not found on the selected data source" in IIS 6 ONLY

It appears to be an issue with the BoundField control element. As suggested in an answer provided by user Anant in the article linked above, you can convert the BoundField to a TemplateField and it will work (using "OrderStatuse.Name" in your example). That solution worked for me.

Although this really doesn't explain why IIS6 can't support the BoundField in this way.

Mind boggling.

like image 159
JamesHough Avatar answered Sep 21 '22 00:09

JamesHough


I found the IIS Version on my server is 6. but my local is 7.5. I publish my project on another server with iis 7.5 and it works

Solution1: I create a summaryOfOrder like this:

class summaryOfOrder
    {
        public int Id { get; set; }
        public int OrderId { get; set; }
        public string ConfirmStatusName { get; set; }
        public string OrderStatusName { get; set; }
        public string PaymentStatusName { get; set; }
        public string ShippingStatusName { get; set; }
        public string CreatedDate { get; set; }


    }

and change

<asp:BoundField DataField="ConfirmStatuse.Name"  />

to

<asp:BoundField DataField="ConfirmStatusName"  />

and bind class to grid by

gv.datasource = mySummryOfOrder; 
gv.databind();

and initialize a list of this type and bind it to grid programmatically

Update solution 2 convert

asp:BoundField

to

asp:TemplateField and using

<%# Eval("Worker.FullName")%>
like image 44
Mohammadreza Avatar answered Sep 20 '22 00:09

Mohammadreza