这是主表单:
<%@ 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="A"></asp:ListItem>
<asp:ListItem Value="B"></asp:ListItem>
<asp:ListItem Value="C"></asp:ListItem>
<asp:ListItem Value="D"></asp:ListItem>
<asp:ListItem Value="E"></asp:ListItem>
<asp:ListItem Value="F"></asp:ListItem>
<asp:ListItem Value="H"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Delete" />
<br />
<br />
</form>
表单中的代码:
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < chkItems.Items.Count; i++)
{
if (chkItems.Items[i].Selected == true)
{
chkItems.Items.RemoveAt(i);
}
}
}
在我的表单中,我希望删除用户选择的项目。然而,如果我选择了3个项目,在用户点击删除后至少还会保留一个项目。我错过了什么?
CheckBoxList
并使其为空怎么办? - Si8