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>