protected void AddCategoryButton_Click(object sender, EventArgs e) { ErrorMessages.InnerHtml = string.Empty; QuoteListWrapper wrapper = new QuoteListWrapper(); Quote quote = (Quote)wrapper.GetQuoteById(GetQuoteId()); if (quote.Categories.Contains(CategoryToAddText.Text)) { ErrorMessages.InnerHtml = "<br>The category you are adding already exists in the list."; return; } //Update our data structure quote.Categories.Add(CategoryToAddText.Text); wrapper.UpdateQuote(quote); //Clear the textbox CategoryToAddText.Text = string.Empty; //Show the change to the user InitializeControl(); }
protected void RemoveButton_Click(object sender, EventArgs e) { Button clicked = (Button)sender; if (clicked == null) return; if (clicked.CommandName == null) return; QuoteListWrapper wrapper = new QuoteListWrapper(); Quote quote = (Quote)wrapper.GetQuoteById(GetQuoteId()); if (quote.Categories.Contains(clicked.CommandName)) { quote.Categories.Remove(clicked.CommandName); } //update our data structure wrapper.UpdateQuote(quote); //Show the change to the user InitializeControl(); }
private void InitializeControl() { string QuoteId = GetQuoteId(); QuoteListWrapper wrapper = new QuoteListWrapper(); IQuote quote = wrapper.GetQuoteById(QuoteId); List<CategoryWrapper> catList = new List<CategoryWrapper>(); foreach (string category in quote.Categories) { CategoryWrapper wrap = new CategoryWrapper(); wrap.Text = category; catList.Add(wrap); } ListView1.DataSource = catList; ListView1.DataBind(); }