Solved

ASP.NET - Referencing a checkbox in a nested repeater

Posted on 2004-10-21
969 Views
Last Modified: 2008-02-01
Hi All:

Having trouble getting my code to see the checkbox I am referencing in the nested repeater. The error is:

"Object variable or With block variable not set."

on this line : "For i = 0 To rptRiskNote.Items.Count - 1"

-- repeater --
<asp:repeater id="rptDivision" runat="server">
<ItemTemplate>
      <b>
            <%# DataBinder.Eval(Container.DataItem, "DivisionDesc")%>
      </b>
      <HR>
      <asp:repeater id="rptRiskNote" runat="server" DataSource='<%# RiskNoteDataBind(DataBinder.Eval(Container.DataItem,"DivisionID")) %>'>
            <HeaderTemplate>
                  <ul>
            </HeaderTemplate>
            <ItemTemplate>
                  <LI>
                        <asp:CheckBox id="chkSel" runat="server"></asp:CheckBox>
                        <asp:Label id="lblID" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container.DataItem, "RiskID")%>'>
                        </asp:Label>
                        <%#DataBinder.Eval(Container.DataItem, "Title") & " .."%>
                        </a></span>
                        <br>
            </ItemTemplate>
            <FooterTemplate>
                  </ul>
            </FooterTemplate>
      </asp:repeater><BR />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
----------------

--- CODE ---
Dim strID As String = ""
        Dim i As Integer

        Dim rptRiskNote = CType(rptDivision.FindControl("rptRiskNote"), Repeater)

        For i = 0 To rptRiskNote.Items.Count - 1
            Dim ckb As CheckBox = CType(rptRiskNote.Items(i).FindControl("chkSel"), CheckBox)

            If ckb.Checked Then
                strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
            End If
        Next
------------
0
Question by:Mitchell_
    5 Comments
     
    LVL 33

    Expert Comment

    by:raterus
    Are you iterating through the items collection of the first repeater?  That is the only way you can successfully access the nested repeater.  There are (or could be) multiple rptRiskNotes within rptDivision, so you can't just directly access it.
    0
     
    LVL 33

    Expert Comment

    by:raterus
    also, what exactly is this code doing?, are you running this on a postback of a repeater event?
    0
     

    Author Comment

    by:Mitchell_
    My goal is to iterate through the checkboxes in the 2nd repeater and make a string out of each ID that is checked off.

    Do you have any sample code I could use? How would I talk to the 2nd repeater by looping through the 1st?
    0
     
    LVL 33

    Accepted Solution

    by:
    Try this

    --
    Dim strID As String = ""

    For Each ri As RepeaterItem In rptDivision.Items

            Dim rptRiskNote as Repeater = CType(ri.FindControl("rptRiskNote"), Repeater)

            For i as integer = 0 To rptRiskNote.Items.Count - 1
                Dim ckb As CheckBox = CType(rptRiskNote.Items(i).FindControl("chkSel"), CheckBox)

                If ckb.Checked Then
                    strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
                End If
            Next

    Next
    0
     

    Author Comment

    by:Mitchell_
    worked! thanks!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now