protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e) { //let's filter books bl = new BookShopBL(ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString); GridView1.DataSource = bl.GetBooksFrom(ddlCountries.SelectedItem.Value); GridView1.DataBind(); }
protected void LoadDataToComponents() { //use try catch always when reading data outside of your code try { bl = new BookShopBL(ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString); ddlCountries.DataSource = bl.GetCountries(); ddlCountries.DataBind(); } catch (Exception ex) { errorMessage.InnerHtml = string.Format("We are sorry, an error is occured in {0}, the system is temporarily out of order.", ex.Source); } }
private void LoadDataToControl() { try { //get connection string to database connStr = ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString; //let's fill the gridview with books bl = new BookShopBL(connStr); GridView1.DataSource = bl.GetAllBooks(); GridView1.DataBind(); } catch (Exception ex) { errorMessage.InnerHtml = ex.Message;//bad error message errorMessage.InnerHtml = string.Format("We are sorry, an error is occured in {0}, the system is temporarily out of order.", ex.Source); } }
protected void btnSearch_Click(object sender, EventArgs e) { try { //Sanity test: Lets check that input is proper Regex regex = new Regex(@"^[a-ö]*$"); if (regex.IsMatch(txtAuthor.Text)) { bl = new BookShopBL(ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString); GridView1.DataSource = bl.GetBooksFromAndBy(ddlCountries.SelectedItem.Value, txtAuthor.Text); GridView1.DataBind(); } else { errorMessage.InnerHtml = " The given text was not proper"; } } catch (Exception ex) { errorMessage.InnerHtml = ex.Message; } }