Hey Im generation some dynamic controls through a repeater control. Im binding through the itemdatabound event on the repeater: if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { PlaceHolder plhCheckboxMemberGroupsContainer = (PlaceHolder)e.Item.FindControl("plhCheckboxMemberGroupsContainer"); plhCheckboxMemberGroupsContainer.EnableViewState = true; SiteUser siteUser = (SiteUser)e.Item.DataItem; Member member = new Member(siteUser.Id); List<MemberGroup> memberGroups = (from DictionaryEntry x in member.Groups select x.Value as MemberGroup).ToList(); CheckBox chkMemberGroup; HtmlGenericControl tableCell; foreach (MemberGroup item in allMemberGroups) { tableCell = new HtmlGenericControl("td"); chkMemberGroup = new CheckBox(); chkMemberGroup.ID = item.Text +"_" + siteUser.Id; chkMemberGroup.EnableViewState = true; if (memberGroups.Contains(item)) { chkMemberGroup.Checked = true;
Im creating some checkboxes inside a placeholder, ive ensured that each checkbox gets a unique id and Im setting the viewstate explicit.
But when Im looping through these repeater controls collection I cant find them, there are gone:
foreach (RepeaterItem item in repSiteUsers.Items) {
foreach (var control in plhCheckboxMemberGroupsContainer.Controls) { if (control is CheckBox) { // do stuff here } }
} I have to create the controls dynamic because it varies how many there are, so I cant write them static in the mark up , which I usually do. Those controls which is are static in the mark up are found, but no the dynamic created controls.
Dynamic created controls
Hey
Im generation some dynamic controls through a repeater control. Im binding through the itemdatabound event on the repeater:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
PlaceHolder plhCheckboxMemberGroupsContainer = (PlaceHolder)e.Item.FindControl("plhCheckboxMemberGroupsContainer");
plhCheckboxMemberGroupsContainer.EnableViewState = true;
SiteUser siteUser = (SiteUser)e.Item.DataItem;
Member member = new Member(siteUser.Id);
List<MemberGroup> memberGroups = (from DictionaryEntry x in member.Groups select x.Value as MemberGroup).ToList();
CheckBox chkMemberGroup;
HtmlGenericControl tableCell;
foreach (MemberGroup item in allMemberGroups)
{
tableCell = new HtmlGenericControl("td");
chkMemberGroup = new CheckBox();
chkMemberGroup.ID = item.Text +"_" + siteUser.Id;
chkMemberGroup.EnableViewState = true;
if (memberGroups.Contains(item))
{
chkMemberGroup.Checked = true;
}
tableCell.Controls.Add(chkMemberGroup);
plhCheckboxMemberGroupsContainer.Controls.Add(tableCell);
}
}
Im creating some checkboxes inside a placeholder, ive ensured that each checkbox gets a unique id and Im setting the viewstate explicit.
But when Im looping through these repeater controls collection I cant find them, there are gone:
foreach (RepeaterItem item in repSiteUsers.Items)
{
foreach (var control in plhCheckboxMemberGroupsContainer.Controls)
{
if (control is CheckBox)
{
// do stuff here
}
}
}
I have to create the controls dynamic because it varies how many there are, so I cant write them static in the mark up , which I usually do. Those controls which is are static in the mark up are found, but no the dynamic created controls.
Any ideas?
Ive forgot this line of code
PlaceHolder plhCheckboxMemberGroupsContainer = (PlaceHolder)item.FindControl("plhCheckboxMemberGroupsContainer");
when im looping through the repeater items
Are you re-binding the repeater every time the page loads?
is working on a reply...