I make this query. LinqSQl
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
}
into d
group d by d.OrderID;
then I want display this data in datagrid
there is my markup:
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="asp1._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="false"
CellPadding="4" ForeColor="#333333" Width="600px">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="Name" />
<asp:BoundField DataField="CustomerName" HeaderText="CustomerName" />
<asp:BoundField DataField="EmployeeName" HeaderText="EmployeeName" />
<asp:BoundField DataField="ShipperName" HeaderText="ShipperName" />
<asp:BoundField DataField="Products" HeaderText="Products" />
<asp:BoundField DataField="TotalPrice" HeaderText="TotalPrice" />
</Columns>
<HeaderStyle BackColor="#7961da" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
</body>
</html>
thus method
Grid.DataSource = query.ToList();
Grid.DataBind();
And I get error: A field or property with the name 'OrderID' was not found on the selected data source.
What is my problem?
because when I use this query
var query1 = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
};
Grid.DataSource = query1;
Grid.DataBind();
I display data, but they aren't grouped.
I get this data
OrderId| CustomerName| EmployeeName |ShipperName | Products| TotalPrice 1 Apple Kevin AIG Iphone 1000 1 Apple Kevin AIG IPAD 1100 2 Samsung John KMP S6 900 2 Samsung John KMP S5 800
I want to get this result.
OrderId| CustomerName| EmployeeName |ShipperName | Products | TotalPrice 1 Apple Kevin AIG Iphone,Ipad 2100 2 Samsung John KMP S6,s5 1700