コード例 #1
0
 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();
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
ファイル: Books.aspx.cs プロジェクト: deaddis/viikkotehtava-1
 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);
     }
 }
コード例 #4
0
 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;
     }
 }