What is the point of removing items from a checkbox list then redirecting? You don't show the changes you are making
Webform2.aspx :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:checkboxlist ID="UPCList" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:checkboxlist>
</div>
<asp:Button ID="btn_remove" runat="server" Text="Remove" OnClick="btn_remove_Click" />
</form>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</body>
</html>
Webform2.aspx.cs :
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Load";
}
public void btn_remove_Click(object sender, EventArgs e)
{
for (int i = 0; i < UPCList.Items.Count; i++)
{
if (UPCList.Items[i].Selected == true)
{
UPCList.Items.RemoveAt(i);
}
}
Label1.Text = "Done";
}
}
}
Works as expected.
If I put in the
Response.Redirect("WebForm2.aspx?account=" + AcctNum.Text);
I get Item 1 ... 6 Remove
and a Label1 that says "Load"
also for clarity's sake i also like to do
foreach (var toRemove in UPCList.Items.OfType<ListItem>().Where(f => f.Selected).ToList())
{
UPCList.Items.Remove(toRemove);
}
but that's just personal opinion.