As you may know the CheckBoxList renders html <input type="checkbox"> and some more (<label ...)
In the description it says that the value is stored in the view state. But what if i do not want to use the viewstate ( <asp:CheckBoxList ID="CheckBoxList1" runat="server" EnableViewState="False">)? I would expect that the code below:
DataTable dt = CameraMakers.GetBrandNamesAsDataTable();
CheckBoxList1.DataSource = dt;
CheckBoxList1.DataValueField = dt.Columns["ID"].ToString();
CheckBoxList1.DataTextField = dt.Columns["description"].ToString();
CheckBoxList1.DataBind();
would produce something like this
<input type="checkbox" name="cb1" value="121"><label for="cb1">Sony</label>
<input type="checkbox" name="cb2" value="122"><label for="cb2">Canon</label>
But even if am willing to accept that asp.net will not use the value property of the input-tag. I expect at least to be able to access the value:
foreach (ListItem listi in CheckBoxList1.Items)
{
if (listi.Selected == true)
{
checkBoxValues += listi.Value;
}
}
But this will not work either if you use CheckBoxList1.DataSource instead of writing the ListItems by Hand in the aspx file (<asp:ListItem>).
Do you agree that the behaviour of this control has lots of room for improvement (<strike>is utter nonesense right now</through>).