Remove Items From a CheckBox List

sugarush

New Member
Here is main form:\[code\]<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckDelete.aspx.cs" Inherits="CheckDelete" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head><body><form id="form1" runat="server"><asp:CheckBoxList ID="chkItems" runat="server" style="width: 37px"> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/A"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/B"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/C"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/D"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/E"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/F"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15599643/H"></asp:ListItem></asp:CheckBoxList><asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Delete" /><br /><br /></form>\[/code\]Code in Form:\[code\]protected void Button1_Click(object sender, EventArgs e){ for (int i = 0; i < chkItems.Items.Count; i++) { if (chkItems.Items.Selected == true) { chkItems.Items.RemoveAt(i); } }}\[/code\]In my form, I want to delete the items that the user has checked off. However, if I select 3 items, at least one item will remain on the form after the user hits delete. What am I missing?
 
Back
Top