Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a linq query in which i am using Group By and i am binding a gridview using this query but gridview is not binding properly in all rows of gridview it shows
"System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType6526[System.Nullable`1[System.Int32],System.String,System.String,System.String,System.String,System.Int32],System.String]"
my aspx page is:
ASP.NET
<Columns>
                            <asp:TemplateField HeaderText="Sl no." ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <div style="margin: 0px auto; width: auto;">
                                        <asp:Label ID="lblslno" runat="server" Text='<%#Container.DisplayIndex+1 %>'>'></asp:Label>
                                        <asp:HiddenField ID="hf" runat="server" Value='<%#Eval("EmpId") %>' />
                                    </div>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Employee Code." DataField="EmpCode" ItemStyle-HorizontalAlign="Center" />
                            <asp:BoundField HeaderText="Employee Name" DataField="Name" />
                            <asp:BoundField HeaderText="Department" DataField="DeptName" />
                            <asp:BoundField HeaderText="Designation" DataField="DesigName" />
                            <asp:TemplateField HeaderText="Total Marks" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblTotalMarks" runat="server" CssClass="Label" Text='<%#Eval("Total_Mark") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Marks Secured" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblMarksSecured" runat="server" CssClass="Label" Text='<%#Eval("Total_Mark") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>


and my code behind is like
C#
var query = (from a in TraningScheduleDetails
                         from b in TraningAnshwerSheet
                         from c in TraningAnshwerSheetDetails
                         from d in EmpProfessionalDetails
                         from e in EmpProfessionalJobDetails
                         from f in Department
                         from g in Designation
                         where a.TrainingScheduleDetailId == int.Parse(ddlExamDate.SelectedValue)
                         && a.TrainingScheduleDetailId == b.TrainingScheduleDetailId
                         && b.TrainingAnswerSheetId == c.TrainingAnswerSheetId
                         && b.EmployeeProfessionalDetailId == d.EmployeeProfessionalDetailId
                         && d.EmployeeProfessionalDetailId == e.EmployeeProfessionalDetailId
                         && e.DepartmentId == f.DepartmentId
                         && e.DesignationId == g.DesignationId
                         select new
                         {
                             b.EmployeeProfessionalDetailId,
                             Name = d.FirstName + " " + d.MiddleName + " " + d.LastName,
                             d.EmployeeCode,
                             f.DepartmentName,
                             g.DesignationName,
                             Total_Mark = total_Mark,
                         }).ToList();
            var query2=(from a in query group a by a.EmployeeProfessionalDetailId into b
                        select new
                        {
                            EmpId=b.Key,                            
                            Name=b.Select(c =>c.Name),
                            EmpCode=b.Select(c=>c.EmployeeCode),
                            DeptName=b.Select(c=>c.DepartmentName),
                            DesigName=b.Select(c=>c.DesignationName),
                            Total_Mark=b.Select(c=>c.Total_Mark),                            
                        }).ToList();           
            grdEmployeeDetails.DataSource = query2;
            grdEmployeeDetails.DataBind();


please help.
Posted
Updated 21-Apr-14 23:27pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900