Hello,
I am having some issue persisting checks of the checkboxlist which is inside a combobox.
My case is little bit different from the one you have proposed in nesting_content_modified.zip in that I would like a bunch of checkboxes to be checked when the user clicks Set Index button.
To do so, I modified your code as follows:
In WebUserControl.ascx
protected void Button2_Click(object sender, EventArgs e)
{
// I want to check the checkboxes 2nd and 3rd
ListItem l;
for (int i = 2; i < 4; i++)
{
l = chkRoles.Items.FindByValue(i.ToString());
if (l != null)
l.Selected = true;
}
}
In WebUserControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("value", typeof(double));
dt.Rows.Add(new object[] { "Jan", 1 });
dt.Rows.Add(new object[] { "Feb", 2 });
dt.Rows.Add(new object[] { "Mar", 3 });
dt.Rows.Add(new object[] { "Apr", 4 });
dt.Rows.Add(new object[] { "May", 5 });
dt.Rows.Add(new object[] { "Jun", 6 });
chkRoles.DataSource = dt;
chkRoles.DataTextField = "Name";
chkRoles.DataBind();
}
For some reason, in this case the two checkboxes do not persist.
Any opinion/feedback is really appreciated.
Thanks