Dynamic checkboxes

B

Bill Youngman

Hi all,

Am developing a page that dynamically generates checkboxes based on the records returned from a datareader - in this case user groups. When the user checks on of the boxes I am trying to get that checkbox to then expand further with checkboxes representing the properties for that user group - like a checkbox treeview.

Here is a code snippet that is being run on Page_Load -

SqlDataReader drUG = UGA.GetUserGroups();

while (dr.Read())
{
CheckBox cbxUG = new CheckBox();
cbxUG.ID = "cbxUG" + drUG.GetValue(0).ToString().Trim();
cbxUG.Text = drUG.GetValue(1).ToString().Trim();
cbxUG.AutoPostBack = true;
cbxUG.EnableViewState = true;

phContainer.Controls.Add(new LiteralControl("<TR>"));
phContainer.Controls.Add(new LiteralControl("<TD>"));
phContainer.Controls.Add(cbxUG);
phContainer.Controls.Add(new LiteralControl("</TD>"));
phContainer.Controls.Add(new LiteralControl("</TR>"));

if (cbxUG.Checked)
{
UGIndex = cbxUG.ID.Substring(5);
SqlDataReader drLC = UGA.GetUserGroupLifeCycles(Convert.ToInt32(UGIndex));

while (drLC.Read())
{
CheckBox cbxLC = new CheckBox();
cbxLC.ID = drLC.GetValue(2).ToString().Trim();
cbxLC.Text = drLC.GetValue(3).ToString().Trim();

phContainer.Controls.Add(new LiteralControl("<TR>"));
phContainer.Controls.Add(new LiteralControl("<TD>"));
phContainer.Controls.Add(cbxLC);
phContainer.Controls.Add(new LiteralControl("</TD>"));
phContainer.Controls.Add(new LiteralControl("</TR>"));
}
}
}

The problem that I am running into is that when I check an item on the PostBack cbxUG.Checked is returning a false for every record. I tried adding an event handler for CheckedChanged without any success - the only way I was able to get the eventhandler to see the checkboxes was to run the same code from above testing for the Checked state in the CheckedChanged function and that wasn't displaying the cbxLC checkboxes.

What am I missing here and also is there a better way to do this?

TIA,
Bill Youngman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top