0

I am using northwind database and try to return product table using linq to sql. below pasted my code.

protected void Page_Load(object sender, EventArgs e)
        {
            DemoDataContext dbContext = new DemoDataContext();
            var lyncQuery = from product in dbContext.Products
                            where product.CategoryID == 2
                            orderby product.UnitPrice descending
                            select product;
            ProductDataGrid.DataSource = lyncQuery;
            Response.Write(lyncQuery.ToString());
            ProductDataGrid.DataBind();
        }
    }

i verified lyncquery returns all the columns by printing that in response.write, when i debug also i am seeing all the columns value in lyncquery but when i am binding that with datagrid i am seeing only productid, productname, discontinued,quantityperunit as below.

enter image description here

even i tried returning specific columns using below in select clause, select new { product.ProductID, product.ProductName, product.CategoryID, product.SupplierID, product.Discontinued, product.UnitPrice, product.QuantityPerUnit };

but still i am seeing only those 4 columns

any lead can help me in resolve this. Thanks in advance

Adeel
  • 2,901
  • 7
  • 24
  • 34
Bala Sm
  • 1
  • 1
  • You can check this entry :https://stackoverflow.com/questions/2393223/binding-linq-query-to-datagridview?answertab=active#tab-top I think it would help you. – CodeThereWish Sep 24 '18 at 09:02

2 Answers2

0

Are you Autogenerating Columns in the GRIDVIEW or you have specified the columns to be shown in the gridview. There may be possibility that you are only displaying these 4 columns. Can you please Add your HTML page code also.

Amit chauhan
  • 540
  • 9
  • 22
0

I think you had to place this data into DataTable And then to provide it to the gridView source then may it will work.