Datagrid not rendering column from linq to sql

72 Views Asked by At

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

2

There are 2 best solutions below

1
Amit chauhan On

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.

0
Ketan_Hirapara On

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