views:

1460

answers:

2

i have used aggregate function in List Page of dynamic datawebsite. When it execute it gives me, DataBinding: 'DynamicClass1' does not contain a property with the name 'EmployeeID'.

  <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
                AllowPaging="True" AllowSorting="True" CssClass="gridview">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:HyperLink ID="EditHyperLink" runat="server"
                                NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
                            Text="Edit" />&nbsp;<asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
                                CausesValidation="false" Text="Delete"
                                OnClientClick='return confirm("Are you sure you want to delete this item?");'
                            />&nbsp;<asp:HyperLink ID="DetailsHyperLink" runat="server"
                                NavigateUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'
                                Text="Details" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>

                <PagerStyle CssClass="footer"/>        
                <PagerTemplate>
                    <asp:GridViewPager runat="server" />
                </PagerTemplate>
                <EmptyDataTemplate>
                    There are currently no items in this table.
                </EmptyDataTemplate>
            </asp:GridView>

            <asp:LinqDataSource ID="GridDataSource" runat="server" 
            ContextTypeName="DataClassesDataContext" 
              TableName="Employees" 
              GroupBy="EmployeeNo"
              Select="new(Key, 
                Max(Version) As VersionNo)"
            EnableDelete="true">
                <WhereParameters>
                    <asp:DynamicControlParameter ControlID="FilterRepeater" />
                </WhereParameters>
            </asp:LinqDataSource>

I have not changed any of the default code except i have added ContextTypeName,TableName, GroupBy and select in Linq Data source... Table "Employees" has "EmployeeID, EmployeeNo, EmployeeName, Department, Address, City, State, Country, Version" as columns..

Any idea how to solve this?

Thanks in advance!

Regards, Bala

+1  A: 

The problem is that you're grouping doesn't create the type of data that the grid is expecting to receive. GetDataItem() is expecting a particular type of data and that's not what you've set up in your LinqDataSource.

Your select needs to include all the items that GetDateItem() needs, right now it doesn't:

new(Key, Max(Version) As VersionNo) //EmployeeID needs to be included here
Joseph
Thanks for the reply Joseph. I have not changed any of the default code except i have added ContextTypeName,TableName, GroupBy and select in Linq Data source...
Tabel Employees has "EmployeeID, EmployeeNo, EmployeeName, Department, Address, City, State, Country, Version" as columns..
Adding Select="new(Key, Max(Version) As VersionNo,EmployeeId)" gives error"No property or field 'EmployeeId' exists in type 'IGrouping`2'". i tried, GroupBy="new(EmployeeNo,EmployeeId)" also. It gives same error!
@Bala I would try removing the grouping first and getting it to work without the grouping. Then I would try building a LINQ query that looks like what you want (not in the markup but in the code behind). That should allow you to formulate what your groupby and your select should be.
Joseph
A: 

new(Key, Max(Version) As VersionNo) is fine.

To Get the Employee... use: Key.Employee

The Key is a dynamic class containing all the properties specified in the group by statement.

Anything else (ie EmployeeNo, EmployeeName, Department, Address, City, State, Country, Version) will need an aggregate statement (ie Sum, Max, Min).

NMVenhola