• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1045
  • Last Modified:

ASP.NET - Referencing a checkbox in a nested repeater

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
Mitchell_
Asked:
Mitchell_
  • 3
  • 2
1 Solution
 
raterusCommented:
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
 
raterusCommented:
also, what exactly is this code doing?, are you running this on a postback of a repeater event?
0
 
Mitchell_Author Commented:
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
 
raterusCommented:
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
 
Mitchell_Author Commented:
worked! thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now