Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What is the point of removing items from a checkbox list then redirecting? You don't show the changes you are making</p> <p><strong>Webform2.aspx :</strong> </p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %&gt; &lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:checkboxlist ID="UPCList" runat="server"&gt; &lt;asp:ListItem&gt;Item 1&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Item 2&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Item 3&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Item 4&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Item 5&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Item 6&lt;/asp:ListItem&gt; &lt;/asp:checkboxlist&gt; &lt;/div&gt; &lt;asp:Button ID="btn_remove" runat="server" Text="Remove" OnClick="btn_remove_Click" /&gt; &lt;/form&gt; &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Webform2.aspx.cs :</strong> </p> <pre><code>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 &lt; UPCList.Items.Count; i++) { if (UPCList.Items[i].Selected == true) { UPCList.Items.RemoveAt(i); } } Label1.Text = "Done"; } } } </code></pre> <p>Works as expected.</p> <p>If I put in the </p> <pre><code>Response.Redirect("WebForm2.aspx?account=" + AcctNum.Text); </code></pre> <p>I get Item 1 ... 6 Remove </p> <p>and a Label1 that says "Load"</p> <p>also for clarity's sake i also like to do </p> <pre><code> foreach (var toRemove in UPCList.Items.OfType&lt;ListItem&gt;().Where(f =&gt; f.Selected).ToList()) { UPCList.Items.Remove(toRemove); } </code></pre> <p>but that's just personal opinion.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload