protected void dropDownEditSearch_SelectedIndexChanged(object sender, EventArgs e) { //Program clears out the current text lbl_result.Text = ""; lbl_error.Text = ""; double isbn = double.Parse(dropDownEditSearch.SelectedValue); double rating = 0; string format = ""; BookInventoryTableAdapters.BookTableAdapter tableAdapter = new BookInventoryTableAdapters.BookTableAdapter(); BookInventory.BookInventoryTableDataTable bookInventory = tableAdapter.GetDataByIsbn(isbn); //Foreach loop goes through the rows foreach (BookInventory.BookInventoryTableRow br in bookInventory) { //Program updates each item with the current information from the database textEditIsbn.Text = br.Isbn.ToString(); textEditFirstName.Text = br.AuthorFName.ToString(); textEditLastName.Text = br.AuthorLName.ToString(); textEditTitle.Text = br.Title.ToString(); cbEditCategory.Items.FindByText("Fiction").Selected = (bool)br.Fiction; cbEditCategory.Items.FindByText("Children's").Selected = (bool)br._Children_s; cbEditCategory.Items.FindByText("Foreign").Selected = (bool)br.Foreign; cbEditCategory.Items.FindByText("Romance").Selected = (bool)br.Romance; cbEditCategory.Items.FindByText("Suspense").Selected = (bool)br.Suspense; cbEditCategory.Items.FindByText("Non-Fiction").Selected = (bool)br._Non_Fiction; cbEditCategory.Items.FindByText("Comedy").Selected = (bool)br.Comedy; cbEditCategory.Items.FindByText("History").Selected = (bool)br.History; cbEditCategory.Items.FindByText("Sci-Fi").Selected = (bool)br._Sci_Fi; cbEditCategory.Items.FindByText("Textbook").Selected = (bool)br.Textbook; cbEditCategory.Items.FindByText("AutoBiography").Selected = (bool)br.Autobiography; cbEditCategory.Items.FindByText("Drama").Selected = (bool)br.Drama; cbEditCategory.Items.FindByText("Horror").Selected = (bool)br.Horror; cbEditCategory.Items.FindByText("Self-Help").Selected = (bool)br._Self_Help; cbEditCategory.Items.FindByText("Thriller").Selected = (bool)br.Thriller; cbEditCategory.Items.FindByText("Biography").Selected = (bool)br.Biography; cbEditCategory.Items.FindByText("Fantasy").Selected = (bool)br.Fantasy; cbEditCategory.Items.FindByText("Religious").Selected = (bool)br.Religious; rating = br.Rating; format = br.Format; } int index = DropDownQuestNum.Items.IndexOf(DropDownQuestNum.Items.FindByValue(rating.ToString())); DropDownQuestNum.SelectedIndex = index; int rbindex = rblst_format.Items.IndexOf(rblst_format.Items.FindByValue(format)); rblst_format.SelectedIndex = rbindex; }
protected void dropDownEditSearch_SelectedIndexChanged(object sender, EventArgs e) { //Program gets the isbn, rating, and format double isbn = double.Parse(dropDownEditSearch.SelectedValue); double rating = 0; string format = ""; //Creating objects for the table adapter and bookInventory BookInventoryTableAdapters.BookTableAdapter tableAdapter = new BookInventoryTableAdapters.BookTableAdapter(); BookInventory.BookInventoryTableDataTable bookInventory = tableAdapter.GetDataByIsbn(isbn); //Foreach loop goes through each row of data foreach (BookInventory.BookInventoryTableRow br in bookInventory) { //Program sets the label text to the current record lblFirstName.Text = br.AuthorFName.ToString(); lblLastName.Text = br.AuthorLName.ToString(); lblTitle.Text = br.Title.ToString(); lblRating.Text = br.Rating.ToString(); rating = br.Rating; format = br.Format; } //Program gets the book categories string categorySql = "SELECT Fiction, [Children's], [Foreign], Romance, Suspense, [Non-Fiction], Comedy, History, [Sci-Fi], Textbook, Autobiography, Drama, Horror, [Self-Help], Thriller, Biography, Fantasy, Religious" + " FROM categories WHERE Isbn = @Isbn"; List <string> categoryNames = new List <string>(); //Program opens a new connection to the database using (SqlConnection con = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = new SqlCommand(categorySql, con)) { //Program executes the query cmd.Parameters.AddWithValue("Isbn", isbn); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { //While loop adds the category names to the list of categories while (reader.Read()) { for (int i = 0; i < 18; i++) { if (reader.GetBoolean(i) == true) { categoryNames.Add(reader.GetName(i).ToString()); } } } } } } string cat = ""; //For loop sets cat to the formatted list of categories for (int i = 0; i < categoryNames.Count; i++) { if (categoryNames.Count - i == 1) { cat += categoryNames[i]; } else { cat += categoryNames[i] + ", "; } } //Program displays the categories lblCategories.Text = cat; }