If the ListItems
of the CheckBoxList are added with aspnet, either in code behind or the .aspx page, ViewState will ensure that it will see those disabled checkboxes as checked, even if they are not send to the server.
protected void Button1_Click(object sender, EventArgs e)
{
List<string> selectedValues = new List<string>();
Label1.Text = "";
foreach (ListItem item in myCheckBoxList.Items)
{
if (item.Selected)
{
selectedValues.Add(item.Value);
Label1.Text += item.Value + "<br>";
}
}
}
And to make the example complete:
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br /><br />
<asp:CheckBoxList ID="myCheckBoxList" runat="server">
<asp:ListItem Text="Blueberry" Value="Blueberry"></asp:ListItem>
<asp:ListItem Text="Raspberry" Value="Raspberry"></asp:ListItem>
<asp:ListItem Text="Blackberry" Value="Blackberry"></asp:ListItem>
<asp:ListItem Text="Strawberry" Value="Strawberry" Enabled="false" Selected="True"></asp:ListItem>
<asp:ListItem Text="Gooseberry" Value="Gooseberry" Enabled="false" Selected="True"></asp:ListItem>
</asp:CheckBoxList>
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />