0

I have a simple static CheckboxList in my form :

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="Groupes.aspx.cs" MaintainScrollPositionOnPostback="true" Inherits="WebApp.Form" %>
    <form runat="server">

          <asp:CheckBoxList ID="CheckBoxList1" runat="server" >
                    <asp:ListItem Text ="Text1" Value="1"  ></asp:ListItem>
                    <asp:ListItem Text ="Text2" Value="2" ></asp:ListItem>
                    <asp:ListItem Text ="Text3" Value="3" Selected="True" Enabled="false></asp:ListItem>
            </asp:CheckBoxList>
    </form>

On a button click event (PostBack) I am trying to retrieve the values of the Selected CheckBoxList items in code behind as shown below :

List<string> selectedValues = CheckBoxList1.Items.Cast<System.Web.UI.WebControls.ListItem>().Where(li => li.Selected).Select(li => li.Value).ToList();

But selectedValues.Count is always 1. Only the ListItem that is Disabled whose Selected is set to "True" is counted :

<asp:ListItem Text ="Text3" Value="3" Selected="True" Enabled="false></asp:ListItem>
Bellatrix
  • 29
  • 1
  • 8
  • Everything is looks fine and it's work while I test. – Divyesh patel Nov 19 '19 at 10:34
  • can you please add more related code which may possible to cause of problem. – Divyesh patel Nov 19 '19 at 10:37
  • I was performing a CheckBoxList1.ClearSelection() on another button click event that precedes the one in which I am trying to get the selected ListItems. But even with that gone, the selectedValues .Count always returns 1 (only the Disabled ListItem whose Selected is set to "True" in the form is counted ) – Bellatrix Nov 20 '19 at 13:53

0 Answers0