protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //populate ItemsInCatalogueListBox var populateItemsInCatalogueListBox = context.StationeryCatalogues.Select(x => x.Description).ToList(); ItemsInCatalogueListBox.DataSource = populateItemsInCatalogueListBox; ItemsInCatalogueListBox.DataBind(); //populate SupplierDDL List <String> supList = new List <String>(); supList = context.Suppliers.Select(x => x.SupplierName).ToList(); SupplierDDL.DataSource = supList; SupplierDDL.DataBind(); //populate CategoryListBox var populateCatInCatalogueListBox = context.StationeryCatalogues.Select(x => x.Category).Distinct().ToList(); CategoryListBox.DataSource = populateCatInCatalogueListBox; CategoryListBox.DataBind(); //allow user to choose the 1st day of the month even if 36month ago the cut // off was eg: 4th var minDate = DateTime.Now.AddMonths(-36); var firstDayOfMonth = new DateTime(minDate.Year, minDate.Month, 1); //set the textbox date FromDate.Attributes["min"] = firstDayOfMonth.ToString("yyyy-MM-dd"); FromDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd"); EndDate.Attributes["min"] = firstDayOfMonth.ToString("yyyy-MM-dd"); EndDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd"); } }
/// <summary> /// Fills the DDL on a filter input /// </summary> /// <param name="input"></param> protected void FillDropList(string input) { SqlDataSource result = NorthwindAccess.GetSuppliersSDS(input); SupplierDDL.AppendDataBoundItems = true; SupplierDDL.DataSource = result; SupplierDDL.DataTextField = "CompanyName"; SupplierDDL.DataValueField = "SupplierID"; SupplierDDL.Items.Clear(); SupplierDDL.DataBind(); SupplierDDL.Items.Insert(0, new ListItem("Now pick a company from[" + SupplierDDL.Items.Count + "]")); SupplierDDL.AutoPostBack = true; }