开发者

Populating data grid view problem not showing products

I have a list view listed with category names coming from database i am trying to populate the data grid view by using selection item in list view by the following method.......

    if (lstviewCatgeories.SelectedItems.Count > 0 && lstviewCatgeories.SelectedItems[0].Group.Name == "catgories")
     {

              string text = lstviewCatgeories.SelectedItems[0].Text.ToString();
                var categorywithids = (from categorytypes in dbentity.categories
                                       where categorytypes.category_Name.Equals(text)
                                       select categorytypes.category_Id).SingleOrDefault();


                var productsbycounts = dbentity.products.GroupBy(x => x.product_Id).Where(a => a.FirstOrDefault().category_Id.Equals(categorywithids))
                                      .Select(a => new
                                      {
                                          productid = a.Key,
                                          productname = a.FirstOrDefault().product_Name,
                                          productimage = a.FirstOrDefault().product_Image,
                                          productdescription = a.FirstOrDefault().product_Description,
                                          stockavailable = a.LongCount(),
                                          productprice = a.FirstOrDefault().product_Price

                                      });
                productsall.DataSource = productsbycounts;
                dgvAllproducts.DataSource = productsall;
                dgvAllproducts.Columns[0].Visible = false;
                dgvAllproducts.Columns[3].Vis开发者_如何转开发ible = false;
                DataGridViewButtonColumn column = new DataGridViewButtonColumn();
                dgvAllproducts.Columns.Add(column);
                column.FlatStyle = FlatStyle.System;
                column.DefaultCellStyle.ForeColor = Color.ForestGreen;
                column.DefaultCellStyle.Padding = new Padding(10, 48, 10, 48);
                column.Text = "Buy";
                column.HeaderText = "Buy";
                column.UseColumnTextForButtonValue = true;
                column.Name = "btnbuy";
         }

why i am not able to see the products even if they are products related to category .......

i have seen count 6 at this line productsall.DataSource = productsbycounts;

would any one pls e help on this.......


I'm not sure but based on the code that you submitted, your assigning the DataSource property of dgvAllproducts (that I think is a DataGridView) to what I think is another control (a DataGridView), i.e. : productsall.

dgvAllproducts.DataSource should be set with a real datasource, not with a DataGridView. Sorry if I'm missing something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜