[RESOLVED] Repeater has no controls in page load
Hi
I have a repeater that during the page load I want to go through all checkboxes and check the ones should be checked.
I am bound to a sqldatasource control.
Here is the code. when I run the for each loop during page load it has nothing for controls.count. I also tried prerender in case the controls werent bound yet.
Any ideas why I cant get the checkboxes?
Code:
<asp:Repeater runat="server" ID="univList" DataSourceID="UnivDS">
<HeaderTemplate>
<a href='javascript:deselect();'>Deselect All</a>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr id='univtr<%# DataBinder.Eval(Container.DataItem, "companyid")%>'>
<td><input type="checkbox" runat="server" ID='univChk' onclick="javascript:toggleRow(this);" text='<%#DataBinder.Eval(Container.DataItem, "companyid")%>' /></td>
<td><%# DataBinder.Eval(Container.DataItem, "companyname")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Code:
For Each check As Control In univList.Controls
If TypeOf check IS HtmlInputCheckBox AndAlso ids.Contains(CTYPE(check, HtmlInputCheckBox).Value) Then
CTYPE(check, HtmlInputCheckBox).Checked = True
End If
Next
Re: Repeater has no controls in page load
Hello,
The repeater has an ItemDataBound event:
http://msdn.microsoft.com/en-us/libr...databound.aspx
This is where I would be tempted to do the work that you mention.
Gary
Re: Repeater has no controls in page load
The problem that you are facing is likely to do with the fact that you are not indexing far enough into the nest of controls that you have within the item template. The table control is a container controls, so you would actually need to check the HasControls property of each control, to decide whether you need to recurse into each Control's Controls property.
Gary
Re: Repeater has no controls in page load
Using the itemdatabound event worked, thanks!
Re: [RESOLVED] Repeater has no controls in page load