user710502
user710502

Reputation: 11471

checkboxlist - how to populate it without setting selected value

I have a checkbox list as follows

                    CheckBoxList checkboxlist = new CheckBoxList();
                    checkboxlist.ID = controlID;
                    checkboxlist.Text = shortLabel;
                    checkboxlist.Width = width;
                    checkboxlist.RepeatColumns = columnnum;
                    checkboxlist.DataSource = furnitureItems;
                    checkboxlist.DataTextField = "ShowValue";
                    checkboxlist.DataValueField = "ShowValue";
                    checkboxlist.SelectedValue = //how can i set this to "nothing";
                    checkboxlist.DataBind();

when i set checkboxlist.selectedvalue = "";, I get an error that selected value must be specified. Is there a way around this?, I want all the checkboxes to show unchecked as the initial state. I would appreciate the help.

Please let me know if there is additional information required.

Upvotes: 2

Views: 781

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

It's not mandatory to specify the SelectedValue. However, if you do it you need to specify a valid value. An empty string is invalid.

If you want to deselect the CheckBoxList, use the SelectedIndex property:

checkboxlist.SelectedIndex = -1:

Upvotes: 3

Related Questions