コード例 #1
0
        protected void CategoryList_SelectedIndexChanged(object sender, EventArgs e)
        {
            // when the dropdown list is used in view 1, this method executes


            if (CategoryList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a category to view the category products.");
                LoadMessageDisplay(errormsgs, "alert alert-info");

                // assigning a null data source and binding it is a good way to clear your grid view
                ProductGridViewV1.DataSource = null;
                ProductGridViewV1.DataBind();
            }
            else
            {
                try
                {
                    ProductController sysmgr = new ProductController();
                    List <Product>    info   = sysmgr.Products_GetByCategories(int.Parse(CategoryList.SelectedValue));
                    if (info.Count == 0)
                    {
                        errormsgs.Add("No data found for the partial product name search");
                        LoadMessageDisplay(errormsgs, "alert alert-info");
                    }
                    else
                    {
                        // should probably figure out how this sorting works
                        info.Sort((x, y) => x.ProductName.CompareTo(y.ProductName));

                        //GridView
                        ProductGridViewV1.DataSource = info;
                        ProductGridViewV1.DataBind();
                    }
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
コード例 #2
0
        protected void CategoryList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CategoryList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a category to view the category products.");
                LoadMessageDisplay(errormsgs, "alert alert-info");
                ProductGridViewV1.DataSource = null;
                ProductGridViewV1.DataBind();
            }
            else
            {
                try
                {
                    ProductController sysmgr = new ProductController();
                    List <Product>    info   = sysmgr.Product_GetByCategory(int.Parse(CategoryList.SelectedValue));
                    //if (info.Count == 0)
                    //{
                    //    errormsgs.Add("No data found for the partial product name search");
                    //    LoadMessageDisplay(errormsgs, "alert alert-info");
                    //}
                    //else
                    //{
                    info.Sort((x, y) => x.ProductName.CompareTo(y.ProductName));

                    //GridView
                    ProductGridViewV1.DataSource = info;
                    ProductGridViewV1.DataBind();

                    //}
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }