I am populating a data table which in turn populates a checkboxlist. I want the items to be selected when they are added. I can do this, however when I add a 2nd -> nth Item, it only keeps the last check box. Is there a way to persist selected check boxes through a bind? here is my current function:
protected void FinalizeAdd_Click(object sender, EventArgs e)
{
VersionDataTable.AddVersionDataTableRow(Convert.ToInt32(VersionDropDown.SelectedValue), ProductDropDown.SelectedItem.Text + " " + VersionDropDown.SelectedItem.Text);
ProductCheckList.DataSource = VersionDataTable;
ProductCheckList.DataValueField = VersionDataTable.VersionIDColumn.ToString();
ProductCheckList.DataTextField = VersionDataTable.VersionTextColumn.ToString();
ProductCheckList.DataBind();
ProductCheckList.Items[ProductCheckList.Items.Count - 1].Selected = true;
}
Thanks for the help in advance.
You have to save the selected items before you databind the CheckboxList again.
For example(sorry for VB.NET, but i think you’ll understand what i mean):