private void PopulateCategoryDropDown()
    {
        InventoryPurchasingController controller = new InventoryPurchasingController();
        List <Category> data = controller.ListAllCategories();

        CategoryDropDown.DataSource     = data;
        CategoryDropDown.DataTextField  = "CategoryName";
        CategoryDropDown.DataValueField = "CategoryID";
        CategoryDropDown.DataBind();
        CategoryDropDown.Items.Insert(0, "[select a Category]");
    }
Exemple #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         // Bind Categories list to CategoriesDropDown and set the initial selected value
         List <string> categoriesList = ToDoItemData.GetCategories();
         categoriesList.Add("ALL");
         CategoryDropDown.DataSource = categoriesList;
         CategoryDropDown.DataBind();
         int currentCategoryIndex = categoriesList.IndexOf(CategoryFilter);
         CategoryDropDown.SelectedIndex = currentCategoryIndex;
     }
 }
        private void PopulateCategoryDropDown()
        {
            var controller = new CategoryController();
            var data       = controller.ListCategories();

            CategoryDropDown.DataSource     = data;
            CategoryDropDown.DataTextField  = nameof(Category.CategoryName);
            CategoryDropDown.DataValueField = nameof(Category.CategoryID);
            CategoryDropDown.DataBind();
            // Let's insert a couple of options at the top of the drop-down
            CategoryDropDown.Items.Insert(0, new ListItem("[select a category]"));
            CategoryDropDown.Items.Insert(1, new ListItem("[no category]", string.Empty));
            // The second inserted item is to accommodate a NULL value for the Product.CategoryID
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Panel3.Visible = false;
                Panel2.Visible = false;
                Panel1.Visible = true;
                string CS = ConfigurationManager.ConnectionStrings["EnrollInJob"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    /**creating SqlCommand for Category DropDown list to sotre category name from database */
                    SqlCommand cmd1 = new SqlCommand();
                    cmd1.CommandText = "Select CategoryId, CategoryName from JobCategory";
                    cmd1.Connection  = con;
                    con.Open();//open connection for all
                    SqlDataReader rdr1 = cmd1.ExecuteReader();
                    CategoryDropDown.DataTextField  = "CategoryName";
                    CategoryDropDown.DataValueField = "CategoryId";
                    CategoryDropDown.DataSource     = rdr1;
                    CategoryDropDown.DataBind();
                    ListItem l1 = new ListItem("Select Category", "-1");
                    CategoryDropDown.Items.Insert(0, l1);

                    rdr1.Close();//close rdr1 SqlDataReader to write another new Query
                    /*******************************************************/
                    /** creating SqlCommand for Location dropdown to store city name from database */
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandText = "Select PinCode,CityName from cities";
                    cmd2.Connection  = con;

                    SqlDataReader rdr2 = cmd2.ExecuteReader();
                    LocationDropDownList.DataTextField  = "CityName";
                    LocationDropDownList.DataValueField = "PinCode";
                    LocationDropDownList.DataSource     = rdr2;
                    LocationDropDownList.DataBind();
                    ListItem selectLocation = new ListItem("Select Location", "-1");
                    LocationDropDownList.Items.Insert(0, selectLocation);
                    rdr2.Close();

                    /***************************************************************/
                }
            }
        }
 //Database connection for Category information to bind it to the Category Dropdownlist
 protected void CategoryBind()
 {
     using (var conn = new MySqlConnection(strcon))
     {
         conn.Open();
         string Query = "SELECT * FROM Category";
         using (var cmd = new MySqlCommand(Query, conn))
         {
             using (var reader = cmd.ExecuteReader())
             {
                 if (reader.HasRows)
                 {
                     CategoryDropDown.DataSource     = reader;
                     CategoryDropDown.DataValueField = "CatId";
                     CategoryDropDown.DataTextField  = "CName";
                     CategoryDropDown.DataBind();
                 }
             }
         }
     }
 }
        protected void InitializeCategoryTree()
        {
            if (!_DisplayCategorySearch)
            {
                ListItemCollection items = new ListItemCollection();
                int st = 1;
                IList <CategoryLevelNode> categories = CategoryParentDataSource.GetCategoryLevels(0);
                foreach (CategoryLevelNode node in categories)
                {
                    string prefix = string.Empty;
                    for (int i = st; i <= node.CategoryLevel; i++)
                    {
                        prefix += " . . ";
                    }
                    items.Add(new ListItem(prefix + node.Name, node.CategoryId.ToString()));
                }

                CategoriesList.DataSource = items;
                CategoriesList.DataBind();

                CategoryDropDown.DataSource = items;
                CategoryDropDown.DataBind();
            }
        }