Example #1
0
        private void GetBooksFromBasket()
        {
            //this method binds the book id to dataveiw after the final choice of book ahas been made so when the user removes an item this updates the gridview accordingly
            if (Session["Cart"] != null)
            {
                using (booksDataContext data = new booksDataContext())
                {
                    List <int> Cart = (List <int>)Session["Cart"];
                    var        book = data.Books.Where(Book => Cart.Contains(Book.bookid));

                    GridView1.DataSource = book;
                    GridView1.DataBind();
                }
            }
        }
Example #2
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         using (booksDataContext Data = new booksDataContext())
         {
             //this is used to query the database from the linq datacontext class
             string bookTitle     = TextBoxBookTitle.Text;
             var    searchResults = Data.Books.Where(Books => (Books.bookTitle.Contains(bookTitle) || bookTitle.Length == 0));
             GridView1.DataSource = searchResults;
             GridView1.DataBind();
         }
     }
     catch (Exception)
     {
         //to redirect the user to the error page if any erros occur in executing the search function
         Response.Redirect("~/error.aspx");
     }
 }