protected void TxtSearch_OnTextChanged(object sender, EventArgs e) { //Setting all the labels visibility to false until data is gathered LblName.Visible = false; LblDept.Visible = false; LblDesc.Visible = false; LblPrice.Visible = false; //Filtering the list of items based on what the user searches for List <Item> filteredItems = _items.FindAll(item => item.Name.ToUpper().Contains(TxtSearch.Text.ToUpper())); if (filteredItems.Count == 0) { //Setting the DropDown to only the items that fit the search criteria DrpSearch.DataTextField = "Name"; DrpSearch.DataValueField = "Name"; DrpSearch.DataSource = _items; DrpSearch.DataBind(); DrpSearch.SelectedIndex = 0; } else { //Setting the DropDown to only the items that fit the search criteria DrpSearch.DataTextField = "Name"; DrpSearch.DataValueField = "Name"; DrpSearch.DataSource = filteredItems; DrpSearch.DataBind(); DrpSearch.SelectedIndex = 0; } }
protected void Page_Load(object sender, EventArgs e) { //Getting a list of all departments and items in the database _departments = _departmentDao.GetDepartments(); _items = _itemDao.GetItems(); if (!IsPostBack) { //Setting the DropDown to only the items that fit the search criteria DrpSearch.DataTextField = "Name"; DrpSearch.DataValueField = "Name"; DrpSearch.DataSource = _items; DrpSearch.DataBind(); DrpSearch.SelectedIndex = 0; } }