protected void SearchProductB_OnClick(object sender, EventArgs e) { string searchValue = serchedValue.Text;//get search value if (searchValue != "") { //set values and take care of unexpected value or null error int orderBy, shopId; try { orderBy = int.Parse(productOrder.SelectedValue); } catch { orderBy = 4; } try { shopId = ((BlShopManager)Session["user"]).ShopId; } catch { shopId = -1; } try { string ch = SearchBy.Items[SearchBy.SelectedIndex].ToString();//get by what to search bool IsSearchName = (ch == "Product name"); if (!IsSearchName && !double.TryParse(searchValue, out double result)) { //if searching by price and search val is not a value error msg MSG.Text = "please a valid price '" + searchValue + "' is not a number"; } else { //get the list by the parameters List <BLProduct> products = BLProduct.Search(searchValue, shopId, IsSearchName, orderBy); UpdateData(products); //set data source MSG.Text = ""; //set text to no error } } catch (Exception exception) { MSG.Text = "please select by what you want to search " + exception.Message;// error massage } } else { MSG.Text = "please type the value you want to search";// error massage } }