Results 1 to 5 of 5

Thread: [RESOLVED] Repeater has no controls in page load

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    180

    Resolved [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<&#37;# 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

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    180

    Re: Repeater has no controls in page load

    Using the itemdatabound event worked, thanks!

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Repeater has no controls in page load

    Good stuff

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width