下面是主要形式有:删除项目从复选框列表
<%@ 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个项目,用户在删除后至少会有一个项目保留在表单中。我错过了什么?
谢谢。你真棒。 – 2013-03-24 14:40:26